[R] How to extract every nth element from a vector

Martyn Plummer plummer at iarc.fr
Wed Mar 28 17:28:51 CEST 2001


On 28-Mar-01 Barry Cooke wrote:
> R-helpers:
> 
> Is there a simple way to extract every nth element from a very long vector?

window() will do this.  For example,
R> x <- 1:100
R> window(x, deltat=10)
 [1]  1 11 21 31 41 51 61 71 81 91
attr(,"tsp")
[1]  1.0 91.0  0.1

This will set the "tsp" attribute, which may be a nuisance, but you can
take this off.

Martyn
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list