[R] Selecting subset of a given vector
Nipesh Bajaj
bajaj141003 at gmail.com
Fri Jul 8 21:16:02 CEST 2011
Hi there, given a numeric vector, I can select numbers within a
specific range. However presently, I have something related but
different problem. Suppose I have a numeric vector. Now take an
arbitrary number. Goal to to chose a specific subset with a given
length, from that given vector, so that those chosen numbers are
centered around that given constant.
Here is one example:
### My original vector
Vec <- rnorm(1000)
### Now chose some arbitrary number
Number <- 0
### Chose the length of the resulting vector
New.Len <- 10
Now I have to chose 10 numbers from 'Vec' around 'Number'. If my 'Vec'
contains one or more zero then those zero(s) also be selected.
Can somebody help me with some pointer how can I achieve that?
Thanks,
More information about the R-help
mailing list