I'm trying to left_join a dataframe across multiple dataframes in a list, here is an example of the list and the dataframe:
list1 = lapply(1:3, function(x) data.frame(x = rnorm(10), y = rnorm(10), z = rnorm(10), fac = sample(c("new","old"), 10, replace = TRUE)))
df_1 = data.frame(fac = sample(c("new","old"),10,replace = TRUE), t = rnorm(10))
Now, I'm sure I can use a for loop and the following to add the dataframe to each component of the list. However, I thought there should be an easy way to do this using lapply, something like:
lapply(list1,function(x) x %>% left_join(x,df_1, by = c("fac")))
Though this isn't working, where am I going wrong? I'm guessing you could also use map somehow from purrr. One important aspect that isn't fully represented in the above example is that I need the dataframe to be joined by matching factors, thus a simple cbind would not suffice.
Thanks