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

Huntsinger, Reid reid_huntsinger at merck.com
Wed Mar 28 18:22:02 CEST 2001


Well, you could do something like u.sample <- u[1+(0:((length(u)-1)%/%n)*n],
but 11,628 isn't that big (well under 1mb) unless you're trying to plot it.
In that case you may want to experiment with how you choose the grid. 

Some things to keep in mind:

1. Linear interpolation is used for points within "delta" (parameter to
lowess()) of each other, so there's no point in having grid points closer
together than this. In S-Plus (don't know offhand in R) the default delta is
1% of the range of the independent variable, so this gives you 100 bins,
from each of which you need only one point.

2. You may want grid density to increase as local smoothness decreases

3. Or you may want grid density to reflect the distribution of the
independent variable or something else.

Hope that helps,


Reid Huntsinger
-----Original Message-----
From: Barry Cooke [mailto:bcooke at ualberta.ca]
Sent: Wednesday, March 28, 2001 10:11 AM
To: r-help at stat.math.ethz.ch
Subject: [R] How to extract every nth element from a vector


R-helpers:

Is there a simple way to extract every nth element from a very long vector?

[The vector I want to sample from is an object returned by lowess(). It is
so long (11,628 pairs of elements) that it is causing non-R-related memory
problems elsewhere. I don't see a better way other than sampling the output
returned from lowess.]

Thanks in advance.

Barry Cooke

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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