Dear R users, I have some R code and trying to understand it. I have a vector myvec [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 and a scaler myscaler [1] 10 The following function: match(myvec,myscaler)!="NA" returns : [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA NA NA NA NA NA I need a return FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE Is there any function to perform this? Any help deeply appreciated. Kind Regards Seyit Ali
On Wed, 19 Feb 2003 skayis at lic.co.nz wrote:> The following function: > match(myvec,myscaler)!="NA" > I need a return > FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE > Is there any function to perform this?Try: myvec == myscaler> z <- c(24, 24, 10, 10, 10, 10, 44, 44, 44, 45, 45, 45, 54, 54, 54, 54,42, 42)> a <- 10> match(z,a)[1] NA NA 1 1 1 1 NA NA NA NA NA NA NA NA NA NA NA NA> which(z == a)[1] 3 4 5 6> z == a[1] FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE -J
On 02/19/03 15:50, skayis at lic.co.nz wrote:>Dear R users, > >I have some R code and trying to understand it. I have a vector > > myvec > [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 > >and a scaler > > myscaler >[1] 10 > >The following function: >match(myvec,myscaler)!="NA" > > returns : > > [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA >NA NA NA NA NA > >I need a return > >FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE > >Is there any function to perform this?myvec==myscaler or the reverse. The scalar is "recycled." -- Jonathan Baron, Professor of Psychology, University of Pennsylvania R page: http://finzi.psych.upenn.edu/
Why not just use "=="?> bb[1] 1 2 3 5 6 3> bb==3[1] FALSE FALSE TRUE FALSE FALSE TRUE HTH steve skayis at lic.co.nz wrote:> Dear R users, > > I have some R code and trying to understand it. I have a vector > > myvec > [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 > > and a scaler > > myscaler > [1] 10 > > The following function: > match(myvec,myscaler)!="NA" > > returns : > > [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA > NA NA NA NA NA > > I need a return > > FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE > > Is there any function to perform this? > > Any help deeply appreciated. > > Kind Regards > > Seyit Ali > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
If you want to test for "NA" (Not a number?) you want is.na() or !is.na() (is not "NA") in your case. On Tuesday, February 18, 2003, at 06:50 PM, skayis at lic.co.nz wrote:> Dear R users, > > I have some R code and trying to understand it. I have a vector > > myvec > [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 > > and a scaler > > myscaler > [1] 10 > > The following function: > match(myvec,myscaler)!="NA" > > returns : > > [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA > NA > NA NA NA NA NA > > I need a return > > FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE > > Is there any function to perform this? > > Any help deeply appreciated. > > Kind Regards > > Seyit Ali > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >
!is.na(match(myvec, myscaler)) is probably what you want. Regards, Andrew C. Ward CAPE Centre Department of Chemical Engineering The University of Queensland Brisbane Qld 4072 Australia andreww at cheque.uq.edu.au Quoting skayis at lic.co.nz:> Dear R users, > > I have some R code and trying to understand it. I have a vector > > myvec > [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 > > and a scaler > > myscaler > [1] 10 > > The following function: > match(myvec,myscaler)!="NA" > > returns : > > [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA > NA NA NA NA NA > > I need a return > > FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE > > Is there any function to perform this? > > Any help deeply appreciated. > > Kind Regards > > Seyit Ali > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Dear R users, I have received many suggestions regarding my following function question. I would like to express my sincere thanks to all R users who replied me. If anybody needs, I can share the answers. Kind Regards Seyit Ali ----- Forwarded by Seyit Kayis/randd/Livestock on 20/02/03 09:03 ----- Seyit Kayis To: r-help at stat.math.ethz.ch 19/02/03 15:50 cc: Subject: function Dear R users, I have some R code and trying to understand it. I have a vector myvec [1] 24 24 10 10 10 10 10 44 44 44 45 45 45 54 54 54 54 42 42 and a scaler myscaler [1] 10 The following function: match(myvec,myscaler)!="NA" returns : [1] NA NA TRUE TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA NA NA NA NA NA I need a return FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE ...FALSE Is there any function to perform this? Any help deeply appreciated. Kind Regards Seyit Ali