Search code examples
rstringpurrrforecast

map_at with just a starting string "Exampl"


I have a list with multiple groupings of variables created by aggregate() from the package hts. I want to map a specific forecasting function depending on the name of the group.

Example of names:

G3/GRSA_
G3/COAR_
G4/COAR_RURA_
...

Basically I want something like

map(list, contains*("COAR"), forecast)

to forecast both G3/COAR_ and G4/COAR_RURA_


Solution

  • Just spread the problem

    names_to_map <- names(example_list) grsa_names <- names_to_map [str_detect(names_to_map , "GRSA")]

    map_at(example_list,names_to_map,example_function)