[R] Subsetting vectors based on condition

From: Mahesh Krishnan <mskrishnan71_at_yahoo.com>
Date: Mon 04 Sep 2006 - 01:06:16 GMT


Hello,

I have a question regarding subsetting of vectors. Here's an example of what I'm trying to do:

vect.1 <- c(76,195, 290, 380)

vect.2 <- c(63, 95, 133, 170, 215, 253, 285, 299, 325, 375)

I would like to subset vect.2 so that it has the same length as vect.1, and its numbers are the first corresponging higher value compared to vect.1.

The output should be:

 final.output = (95, 215, 299, NA)

What is the fastest/most eficient way to accompllish this in R?

Thanks for the help in advance,

Mahesh Krishnan



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon Sep 04 16:36:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.