[R] Weird operator behaviour
Peter Alspach
Peter.Alspach at plantandfood.co.nz
Tue Nov 3 23:09:04 CET 2009
Tena koe James
Have you tried something like !fish$Species%in%c('CRA','PHC')?
HTH ....
Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of jimdare
> Sent: Wednesday, 4 November 2009 11:02 a.m.
> To: r-help at r-project.org
> Subject: [R] Weird operator behaviour
>
>
> Hi,
>
> I have a dataset called 'fish'. fish$Species returns extract
> 1. When I use fish$Species != c("CRA","PHC"), i.e. I want
> all species except "CRA" and "PHC", I get extract 2 which is
> blatantly wrong. Can anyone see what I'm doing wrong?
>
> Regards,
> James
>
>
> EXTRACT 1
>
> > fish$Species
> [1] ALB ALB ALB ALB ALB ALB ALB ALB ALB ALB ALB ALB ALB ALB
> ALB ALB ATO ATO [19] ATO ATO ATO ATO ATO ATO BIG BIG BIG BIG
> BIG BIG BIG BIG BIG BIG BIG BIG [37] BIG BIG BWS BWS BWS BWS
> BWS BWS BWS BWS BWS BWS BWS BWS BWS BWS BWS CRA [55] CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA [73] CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA [91] CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA [109] CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA [127] CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA [145] CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA [163] CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA [181] CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA [199]
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA [217] CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA [235] CRA CRA CRA CRA CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA [253] CRA CRA CRA
> CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA CRA
> [271] CRA CRA CRA CRA CRA CRA CRA CRA MAK MAK MAK MAK MAK MAK
> MAK MAK MAK MAK [289] MAK MAK MAK MAK MAK MOO MOO MOO MOO MOO
> MOO MOO MOO MOO MOO MOO MOO MOO [307] MOO MOO PHC PHC PHC PHC
> PHC PHC PHC PHC PHC PHC PHC PHC PHC PHC PHC PHC [325] PHC PHC
> PHC POS POS POS POS POS POS POS POS POS POS POS PTO PTO PTO
> PTO [343] PTO PTO PTO PTO PTO PTO PTO PTO PTO PTO PTO RBM RBM
> RBM RBM RBM RBM RBM [361] RBM RBM RBM RBM RBM RBM RBM RBM SKJ
> SKJ SKJ SKJ SKJ SKJ SKJ SKJ SKJ SKJ [379] SKJ SKJ SKJ SKJ SKJ
> STM STM STM STM STM STM STM STM STN STN STN STN STN [397] STN
> STN STN STN STN STN STN STN STN STN STN STN STN STN STN STN
> STN STN [415] SWO SWO SWO SWO SWO SWO SWO SWO SWO SWO SWO SWO
> SWO SWO SWO SWO TOR TOR [433] TOR TOR TOR TOR TOR TOR YFN YFN
> YFN YFN YFN YFN YFN YFN YFN YFN YFN YFN [451] YFN YFN YFN YFN
> 17 Levels: ALB ATO BIG BWS CRA MAK MOO PHC POS PTO RBM SKJ
> STM STN SWO ...
> YFN
>
> EXTRACT 2
>
> > fish$Species != c("CRA","PHC")
> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE [13] TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE [25] TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [37]
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE [49] TRUE TRUE TRUE TRUE TRUE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE [61] FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE [73] FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
> TRUE [85] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE [97] FALSE TRUE FALSE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE [109] FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> [121] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
> TRUE FALSE TRUE [133] FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE [145] FALSE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE [157]
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE TRUE [169] FALSE TRUE FALSE TRUE FALSE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE [181] FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE [193] FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
> TRUE [205] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE [217] FALSE TRUE FALSE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE [229] FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> [241] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
> TRUE FALSE TRUE [253] FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE [265] FALSE TRUE FALSE
> TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE [277]
> FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE [289] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE [301] TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE [313] TRUE
> FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> FALSE [325] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE [337] TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE [349] TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> [361] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE [373] TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE [385] TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [397]
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE [409] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE [421] TRUE TRUE TRUE TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [433] TRUE
> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE [445] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
>
> --
> View this message in context:
> http://old.nabble.com/Weird-operator-behaviour-tp26163604p2616
> 3604.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list