Hi listers, I have a problem in identifying a value between two vectors... Suppose vector A is... 0.0000 0.0909 0.0909 0.1818 0.2727 0.3636 0.4545 0.6363 0.0000 0.0000 0.0000 0.0000 And vector B is... 3 5 7 18 43 85 91 98 100 130 230 487 I would like to identify the value of vector B that vector A is bigger than 0.5, this means that I want to identify the 9-th value of vector B, that is 98. I know how to do that if I had the both vectors as a matrix, but I want to do this procedure with two vectors... Any suggestions... Thanks in advance, Marcio -- View this message in context: http://www.nabble.com/Select-value-according-two-vectors...-tp24589588p24589588.html Sent from the R help mailing list archive at Nabble.com.
MarcioRibeiro wrote:> > I have a problem in identifying a value between two vectors... > Suppose vector A is... > 0.0000 0.0909 0.0909 0.1818 0.2727 0.3636 0.4545 0.6363 0.0000 0.0000 > 0.0000 0.0000 > And vector B is... > 3 5 7 18 43 85 91 98 100 130 230 487 > I would like to identify the value of vector B that vector A is bigger > than 0.5, this means that I want to identify the 9-th value of vector B, > that is 98. > I know how to do that if I had the both vectors as a matrix, but I want to > do this procedure with two vectors... > >Not much of a difference... a=c(0.0000,0.0909,0.0909,0.1818,0.2727,0.3636,0.545,0.6363, 0.0000,0.0000,0.0000,0.0000) b= c(3,5,7,18,43,85,91,98,100,130,230,487) b[min(which(a>0.5))] #but fails ungraciously if there is no solution # better use a dataframe or matrix and sort set.seed(4711) ab = data.frame(a=rnorm(10),b=rnorm(10)) ab = ab[order(ab$a),] ab$b[min(which(ab$a>0.5))] # ok, not very nice if there is no solution Dieter -- View this message in context: http://www.nabble.com/Select-value-according-two-vectors...-tp24589588p24589952.html Sent from the R help mailing list archive at Nabble.com.
On Jul 21, 2009, at 11:11 AM, MarcioRibeiro wrote:> > Hi listers, > I have a problem in identifying a value between two vectors... > Suppose vector A is... > 0.0000 0.0909 0.0909 0.1818 0.2727 0.3636 0.4545 0.6363 0.0000 > 0.0000 0.0000 > 0.0000 > And vector B is... > 3 5 7 18 43 85 91 98 100 130 230 487 > I would like to identify the value of vector B that vector A is > bigger than > 0.5, this means that I want to identify the 9-th value of vector B, > that is > 98. > I know how to do that if I had the both vectors as a matrix, but I > want to > do this procedure with two vectors... > Any suggestions... > Thanks in advance, > Marcio> B <- scan(textConnection("3 5 7 18 43 85 91 98 100 130 230 487")) Read 12 items > A <- scan(textConnection("0.0000 0.0909 0.0909 0.1818 0.2727 0.3636 0.4545 0.6363 0.0000 0.0000 0.0000 0.0000")) Read 12 items > B[ which(A > 0.5) ] [1] 98 David Winsemius, MD Heritage Laboratories West Hartford, CT