I am trying to do an exercise to become more familiar with how to use the map function in purrr. I am creating some random data (10 columns of 10 datapoints) and then I wanted to use map to perform a series of regressions (i.e. lm(y ~ x, data = )) over the resulting columns in the data frame.
If I just repeatedly use the first column as 'y', I want to perform 10 regressions with each column from 1 to 10 as 'x'. Obviously the results are unimportant - it's just the method. I want to end up with a list of 10 linear model objects.
list_of_vecs <- list()
for (i in 1:10){
list_of_vecs[[paste('vec_', i, sep = '')]] <- rnorm(10,0,1)
}
df_of_vecs <- as.data.frame(list_of_vecs)
Here, I get stuck:
map(df_of_vecs, ~ lm(df_of_vecs[[1]] ~ . ?)
Any tips would be appreciated.
Thanks.