Hi Rstudio Community,
I do not know if what I want to do is possible without using loops: suppose I have a vector of length 1000. I want to use
head() on this vector and store the result in the first element of a list,
list_result. Then, I want to update (or replace) my starting vector with
tail(vector, -5) and do the step described before again, but storing the result in the second element of the list. This means that at the end,
list_result will be a list with 200 elements, each containing a vector of length 5. I don’t think there’s a way of doing that using the tools that
purrr provides, since the list needs to be modified at each iteration.
EDIT: I’m thinking of something like a
map() function that would take a list, and a function that returns a list containing the computation you’re interested in (in this case the result of
head) and the updated list as the second element (in this case, the result of
tail) and would then continue doing that until the list is empty and finally return a list containing only the result of the computations. Does that make sense?