two argument function in purrr:: modify

Hello,

I create simple function with two argument:

piv_fun = function(s, var){
  s %>% filter(!(`Month from Start Date`==(-1)&SICR!='MPD')) %>%
    group_by(`Month from Start Date`, var) %>%
    summarise(perc = n()) %>%
    pivot_wider(names_from = `Month from Start Date`, values_from = perc) %>%
    rename("init" = `-1`) %>%
    modify_if( is.numeric, function(x) x / sum(x, na.rm = T))%>%
    modify_if( is.numeric, round,digits = 4)
  
}
  

this function takes two argument, data.frame and variable, and return some summarized data.frame.

I want two use this function in list of data.frames. I try to use modify function, but I don't know how to specify second argument in modify function.
Is there any solution?

You can use modify2(). It works with if in the example.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.