[R] how to compare 2 numeric vectors

dxc13 dxc13 at health.state.ny.us
Mon Sep 17 21:48:07 CEST 2007


useR's

I am trying to compare two vectors that have the same length.  More
specifically, I am interested in comparing the corresponding positions of
each element in the vector. 

Consider these two vectors of length 20:

v1 <-  2    2    4    NA  NA  NA  10  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA 
NA  NA  NA
v2 <-  NA  4  NA    NA  NA  NA  10  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA 
NA  100 NA

I am only interested in extracting the position number where both vectors
are not equal to NA at the same position.
For example, the second element of both vectors is not equal to NA, and thus
I want to return '2'; similary, I also would want to have '7' returned
because the seventh element of both arrays is not equal to NA.

In general, I would like to find a way to do this for any number of given
positions between the two vectors that satisfy this.  If no positions
satisfy this, then return '0'

I would like to store the results as an object.

If anyone has any ideas, I would greatly appreciate it. Thanks!

dxc13
-- 
View this message in context: http://www.nabble.com/how-to-compare-2-numeric-vectors-tf4469582.html#a12743842
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list