I'm working on a loop where my input is a big data frame and my output would be multiples dataframes.
In my loop there is a nested loop, where I use assign(paste0('small_df', x, y,sep = ''),big_df)
to create multiple df who I can work with. And it works ! But later I'm trying to do the same (exactly) but with my new df, and it doesn't really work, I only have one df at the end, and I don't have any error message.
i've checked, but I don't have NA or zero in any of my df and it's the same code line. I don't understand where the error is coming from... Do you have any idea why it doesn't work ?
so this is my code:
for (x in 1:ncol(xdata)) {
for (y in 1:ncol(ydata)) {
df<- data.frame(iso3c = c(data$iso3c),
date= c(data$date),
x= c(xdata[,x]),
y= (ydata[,y]))
df<- df[!is.na(df$x),]
df<- df[!is.na(df$y),]
assign(paste0('all_df', x, y,sep = ''),prems)
all_df <- lapply(ls(pattern="all_df"), function(x) get(x))
for (i in length(all_df)) {
datyr<-filter(all_df[[i]],date == yr)
data2<-data.frame(datyr)
sumyr<- lm(data2[ ,4]~log(data2[ ,3]), data2)
assign(paste0('final_year', -x, -y,sep = ''),final_year)
}
}
}
Thank you.