Extract every nth element of a vector

后端 未结 4 1975
醉酒成梦
醉酒成梦 2020-11-28 04:07

I would like to create a vector in which each element is the i+6th element of another vector.

For example, in a vector of length 120 I want to create an

4条回答
  •  长情又很酷
    2020-11-28 04:40

    Another trick for getting sequential pieces (beyond the seq solution already mentioned) is to use a short logical vector and use vector recycling:

    foo[ c( rep(FALSE, 5), TRUE ) ]
    

提交回复
热议问题