suppressPackageStartupMessages(library(purrr))
paste0("X",seq(1:6)) -> the_factors
mk_frame <- function(X) {
the_frame <- data.frame(matrix(1:20,
ncol = 4,
nrow = 5))
colnames(the_frame) <- c("X_var", "Y_var", X, "iteration")
the_frame$poly <- as.factor(X)
return(the_frame)
}
map(the_factors,mk_frame) -> list_of_dat
list_of_dat[[1]]
#> X_var Y_var X1 iteration poly
#> 1 1 6 11 16 X1
#> 2 2 7 12 17 X1
#> 3 3 8 13 18 X1
#> 4 4 9 14 19 X1
#> 5 5 10 15 20 X1
list_of_dat[[2]]
#> X_var Y_var X2 iteration poly
#> 1 1 6 11 16 X2
#> 2 2 7 12 17 X2
#> 3 3 8 13 18 X2
#> 4 4 9 14 19 X2
#> 5 5 10 15 20 X2
Created on 2020-09-12 by the reprex package (v0.3.0)