Вы можете использовать mapply
, чтобы применить функцию к двум аргументам (вектор символов и список data.frame), а затем связать результат mapply с помощью do.call:
.
# data.frame simulation
df <- structure(list(date = c("23.08.2018", "24.08.2018", "27.08.2018"
), dfs = structure(list(structure(list(id = structure(2:1, .Label = c("5",
"ind-8cf04a9734132302f96da8e113e80ce5-0"), class = "factor"),
title = structure(1:2, .Label = c("title1", "title2"), class = "factor"),
street = structure(1:2, .Label = c("street1", "street2"), class = "factor")), class = "data.frame", row.names = c(NA,
-2L)), structure(list(id = structure(1L, .Label = "3", class = "factor"),
title = structure(1L, .Label = "title3", class = "factor"),
street = structure(1L, .Label = "street3", class = "factor")), class = "data.frame", row.names = c(NA,
-1L)), structure(list(id = structure(2:1, .Label = c("5", "ind-4dbe13088312d7841a318997b1426dd0-3"
), class = "factor"), title = structure(1:2, .Label = c("title4",
"title5"), class = "factor"), street = structure(1:2, .Label = c("street4",
"street5"), class = "factor")), class = "data.frame", row.names = c(NA,
-2L))), class = "AsIs")), class = "data.frame", row.names = c(NA,
-3L))
# extract and concatenate the data
dfs <- mapply(function(x, y) {
y$date <- x
y
} , df$date, df$dfs, SIMPLIFY = FALSE)
do.call(rbind, dfs)
Выход:
id title street date
23.08.2018.1 ind-8cf04a9734132302f96da8e113e80ce5-0 title1 street1 23.08.2018
23.08.2018.2 5 title2 street2 23.08.2018
24.08.2018 3 title3 street3 24.08.2018
27.08.2018.1 ind-4dbe13088312d7841a318997b1426dd0-3 title4 street4 27.08.2018
27.08.2018.2 5 title5 street5 27.08.2018