'How to assign unique id to a list of dataframes AND apply other functions in one call

I have code that assigns a unique.id to each data frame in my.list and left_joins them with new.df.

new.list = list(data.frame(x = c(1, 2), y = c("a", "b")), data.frame(x = c(1, 2), y = c("b", "b")))
new.df = data.frame(x = c(1, 2), y = c("a", "b"), z = c(1, 2))

new.list = Map(cbind, my.list, unique.id = (1:length(my.list)))

new.list = lapply(new.list, function(x) left_join(x, new.df))

How can you write this with one call preferably just using tidyverse?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source