Combine specific objects into a list
"a" is a list.
> a<-list(1,2,3,c(4,5),6,7)
> a
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4 5
[[5]]
[1] 6
[[6]]
[1] 7
"b" is a conversion indicator.
b<-c(3,2,1)
I want to group (or combine) objects in "a" according to the number in "b", this means that the first 3 groups of objects are together, and then the next two, finally, the last, expected result is as follows:
[[1]]
[1] 1 2 3
[[2]]
[1] 4 5 6
[[3]]
[1] 7
I can use "cumsum" to summarize the three groups, but I don’t know how to display each object as described above. Thank.
+4