I’m running a loop that creates a large number (n) of dataframes called df-1 , df-2, df-3 up to df-n.
Next, I would like to create a list that contains all these dataframes:
listofdf = list(df-1, df-2, df-3, ... df-n)
I suppose I need a function that creates a list of all objects whose name contains "df-", this list is then input into the list() function. I’m stuck on the first part, though.
Edit: Thanks for the comments, as suggested, I found a better solution:
finaldata = NULL
for (i in 1:n) {
df <- function(xyz)
rbind(finaldata, df)
}
My intention was to bind a list of dataframes together to finaldata in a separate step, but with this solution I don’t need a list in the first place.
>Solution :
Making the comment of @mhovd a bit more specific:
listofdf <- vector("list", length = n)
names(listofdf) <- paste0("df_", seq_len(n))
for (i in seq_len(n)) {
do something smart that generates df temp
listofdf[[i]] <- temp
}