0
  df <- tibble::tribble(  ~sev_curve, ~curve_type,  ~trend_date, ~weight,
                          "MILO",  'HOSPITALS',   '7/1/2020',      0.4,
                          'ALSO',  'PHYSICIANSC', '7/1/2020',      0.6)

df %>% mutate(c=purrr::pmap(df, function(#how to reference columns?) {...}))

So I need to use purrr::map to apply a function on each row of the above dataframe. However, only the columns sev_curve and weight are certain to be there. The other 2 columns may be there or may not be there and there may be other columns that could take their place, etc.

1 Answers1

0

We can use select and remove the columns in the standard way with - or one_of

library(dplyr)
library(purrr)
df %>%
     mutate(new = pmap_int(select(., -sev_curve, -weight), ~ n_distinct(c(...))))
akrun
  • 874,273
  • 37
  • 540
  • 662