在多个列(超过2个)上使用purrr:map

时间:2018-12-20 18:58:20

标签: r purrr pmap

我有以下数据-

structure(list(k = structure(c(17563, 17591, 17622, 17652, 17683
), class = "Date"), startdt = structure(c(17532, 17561, 17589, 
17620, 17650), class = "Date"), enddt = structure(c(17560, 17588, 
17619, 17649, 17652), class = "Date")), row.names = c(NA, -5L
), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), .Names = c("k", 
"startdt", "enddt"), vars = "k", drop = TRUE, indices = list(
0L, 1L, 2L, 3L, 4L), group_sizes = c(1L, 1L, 1L, 1L, 1L), 
biggest_group_size = 1L, labels = structure(list(
k = structure(c(17563, 17591, 17622, 17652, 17683), class = "Date")), 
row.names = c(NA, 
-5L), class = "data.frame", vars = "k", drop = TRUE, .Names = "k"))

,我想将其传递给函数。这就是我将如何使用map3的方法,它不存在(万岁)-

dates %>% map3_df(.x = $.k, .y = $.startdt, .z = $.enddt,
 .f = ~ fetchdata(startdate = .z, enddate = .z, k = .x)

可以选择Pmap吗?我只是不太熟悉,一个问题似乎是我无法显式分配变量(即.x,.y,.z),而我想映射的函数需要大量可选变量(而我只想指定startdate,enddt和k)。

任何帮助表示感谢,谢谢。

0 个答案:

没有答案