0

I have the following data --

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"))

and I want to pipe it into a function. here's how I would use map3, which does not exist (hooray) --

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

Pmap may be an option? i'm just not too familiar, and an issue seems to be that i can't assign variables explicitly (ie .x, .y, .z) and the function i want to map to takes a ton of optional variables (and i only want to specify startdate, enddt, and k).

Any help appreciated, thanks in advance.

jsg51483
  • 193
  • 1
  • 10
  • Give `pmap` a try. What is `fetchdata` ? – markus Dec 20 '18 at 19:00
  • can you give me some type of example? i guess what i dont know is the nomenclature to map variables specifically... why i asked here rather than banging my head against the wall. fetchdata is a placeholder, it's my own function i built that pulls/summarizes price data from an internal db. takes arguments such as price hub, startdate, enddate, contract, and bunch of optional, boolean arguments. the thing im not sure of, is how to make sure that the correct columns get mapped to the correct parameters, as there are only 3 columns but far more potential parameters. – jsg51483 Dec 20 '18 at 19:10
  • There was a similar question a couple of minutes ago: https://stackoverflow.com/questions/53874291/purrrpmap-with-other-default-inputs Ask here again if this post doesn't help. – markus Dec 20 '18 at 19:17
  • 1
    nailed it. dates %>% pmap_df(.f = ~ fetchdata(k = ..1, startdt = ..2, enddt = ..3)) thank you so much. – jsg51483 Dec 20 '18 at 19:31
  • 1
    If you figured out what works, you're allowed to post an answer to your own question – camille Dec 20 '18 at 20:29

0 Answers0