Re: [R] Selecting subset of a given vector

2011-07-08 Thread Dennis Murphy
Hi: Do you want the N points in the vector closest to a fixed point? If so, then try this: f <- function(vec, center, nselect) { d <- (vec - center)^2 vec[order(d)][1:nselect] } v <- rnorm(1000) f(v, 0, 10)# select the ten points in v closest to zero Your goal is subject to multip

Re: [R] Selecting subset of a given vector

2011-07-08 Thread David Winsemius
On Jul 8, 2011, at 3:16 PM, Nipesh Bajaj wrote: 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 wi

[R] Selecting subset of a given vector

2011-07-08 Thread Nipesh Bajaj
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 t