0

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_

markus
  • 24,556
  • 5
  • 34
  • 51
Bruno
  • 3,911
  • 1
  • 8
  • 26
  • Please give a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). But consider to use `grep()`. – markus Nov 01 '18 at 16:20
  • I think you could be interesting in `map_if` that apply a function on list element based on a predicate. – cderv Nov 03 '18 at 14:26

1 Answers1

0

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)

Bruno
  • 3,911
  • 1
  • 8
  • 26