Given a list (a) and a numeric vector (b) of the same length as a:
a <- list(1, c(3, 7), 5)
b <- c(1,1,2)
How to create a new list of length max(b) where every element in a is put in the corresponding index according to b and combined if multiple occurrences occur, so that you get:
[[1]]
[1] 1 3 7
[[2]]
[1] 5
This should hopefully be done very efficiently (no loops), as the dimensions of my data tends to be very big…
I’m quite sure there is an obvious solution I haven’t thought about…
Thanks for the help
What about: