I would like to create multiple data frames and assign them based on years. I have seen other posts but I couldn't duplicate it for my case. For example,
a <- c(1,2,3,4)
b <- c('kk','km','ll','k3')
time <- (2001,2001,2002,2003)
df <- data.frame(a,b,time)
myvalues <- c(2001,2002,2003)
for (i in 1:3)
{ y[[i]]<- df[df$time=myvalues[[i]],}
I would like to create three dataframes y1, y2, y3 for years 2001, 2002 and 2003. Any suggestions how do using a for loop?
y = list(), use==not=for testing equality, and you have unmatched brackets in your loop,{y[[i]] <- df[df$time == myvalues[i],]}. However instead of the for loop you can just doy = split(df, df$time)list2env(split(df, df$time), .GlobalEnv)