Index and sublist a list

Viewed 22

i have a list with 150 elements. I want to retrieve just the elements with index (1 2 11 12 21 22 31 32 41 42 51 52 61 62 71 72 81 82 91 92 101 102 111 112 121 122 131 132 141 142) and then i want to get 15 sublist of them. (like with 1 and 2, 11 and 12 etc.)

How could i do that?

> values[1:5]
[[1]]
[1] 7.168749

[[2]]
[1] 5.715637

[[3]]
[1] 0.4676287

[[4]]
[1] 2.933335

[[5]]
[1] 54.53099

> length(values)
[1] 150
1 Answers

We could use seq

i1 <- seq(1, 141, by = 10)
i2 <-c(rbind(i1, i1+1)) 
values[i2]

where i2 will be

> i2
 [1]   1   2  11  12  21  22  31  32  41  42  51  52  61  62  71  72  81  82  91  92 101 102 111 112 121 122 131 132 141
[30] 142
Related