I have a loop within a function. Every repetition of the loop creates a dataframe with 100 rows and 8 columns. I want every such dataframe to be saved as a list item in a list, where the name of that list item corresponds to the name of x[i] in the function, where those names are "Var1", "Var2", "Var3".
However, for every loop my list item is just overwritten.
Func <- function(List, x){
List <- list()
{Loop that creates a data frame "df"}
List[[x[i]]] <- df
}
Output <-
Func(
Dataframe,
c(
"Var1",
"Var2",
"Var3",
)
)
Any ideas appreciated!
Edit:
Another possibility would be to simply have the dataframes named differently within the loop, something I also dont know how to achieve. For example:
Func <- function(List, x){
{loop that creates df_with_new_name_for_each_iteration}