r - How to add list of vector to list of data.frame objects as new slot by parallel? -


i have list of vector different dimension , list of different data.frame objects respectively. want add vec.list df.list parallel new attributes. how can make happen in fastest way? in advance

toy data

df.list <- list(   d1 <- data.frame(     v1=seq(1, by=2, len=6), v2=seq(6, by=2, len=6),     v3=letters[seq(1:6)], v4=sample(1:10, 6, replace = false)),   d2 <- data.frame(     v1=seq(2, by=3, len=8), v2=seq(6, by=3, len=8),     v3=letters[seq(1:8)], v4=sample(1:10, 8, replace = false)),   d3 <- data.frame(     v1=seq(4, by=3, len=5), v2=seq(9, by=3, len=5),     v3=letters[seq(1:5)], v4=sample(1:8, 5, replace = false)) ) 

the vector want add them parallel:

vec.list <- list(sc1 <- c(1,3,5,6,7,8),                   sc2 <- c(2,4,5,7,9,10,14,16),                   sc3 <- c(6,10,11,13,15)) 

try this:

library(dplyr) library(purrr)  df.list.new <- map2(.x = df.list ,                      .y = vec.list ,                      .f = function(x, y) bind_cols(x, data.frame('sc' = y))) 

Comments