I need to purrr::map several elements of a nested list. For example, map(list,1)
gives me the 1st element of each list in the nested list. The problem is that I need to apply it several times. How could I apply it in a sequence of pre-defined numbers? Example as follows:
# Nested list
df <- list(
list(
seq(0,100, length.out = 1000),
seq(0,500, length.out = 1000),
seq(0,700, length.out = 1000)),
list(
seq(200,300, length.out = 1000),
seq(500,5000, length.out = 1000),
seq(200,900, length.out = 1000)
)
)
# My sequence
myseq <- seq(1,3, by = 1)
I would like to do something like map(df,myseq)
in order to automatically do the sequence: map(df,1)
, map(df,2)
, and map(df,3)
but of course it does not work.
Any thoughts?