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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Mar 2001, Barry Cooke wrote:> 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.]seq(1,11628,length=1000) will give 1000 evenly spaced numbers from 1:11628 that you can then index with. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Barry Cooke wrote:> > R-helpers: > > Is there a simple way to extract every nth element from a very long vector?vec[seq(n, length(vec), n)]> [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.]Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- Apply function to every 'nth' element of a vector
- plotting with a symbol on every nth point
- selecting every nth item in the data
- Plotting series marked with a symbol on every nth data point, preferably in ggplot...
- How to calculate mean of every nth time series data with zoo or xts ?