Saving output of for loop in separate data frames

后端 未结 1 1031
余生分开走
余生分开走 2021-01-21 03:51

I\'ve got a simple problem that I haven\'t been able to solve despite the many similar posts, because I\'m a bit of a knucklehead in R, and I\'m not getting whatever it is I sho

1条回答
  •  春和景丽
    2021-01-21 04:14

    for (i in All.Files) {
    a <- get(i)
       for (j in all.files) {
         b <- get(j)
         d <- dataframe(mergefun(a, b))
         newname <- paste("C", substr(j, 9, 12), sep="")
         names(d) <- c("Id", "Country", "logGDP", "GRI", "GRI.group", "Year")
         assign(newname,d)
    
       }  
    }
    

    I fixed your bracketing. It should also be clear that since your newname only relies on j that it will be the case that your new variables will only be created on the LAST iteration of the outer for loop. Thus, you end up with only length(all.files) variables.

    0 讨论(0)
提交回复
热议问题