[R] Logical statements and subseting data...

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Feb 25 15:59:15 CET 2008


Neil,

Maybe this example will make things more clear to you.

> DF <- expand.grid(A = 0:1, B = 0:1)
> cbind(DF, DF$A != 0, DF$B != 0, DF$A != 0 & DF$B != 0, DF$A != 0 |
DF$B != 0)
  A B DF$A != 0 DF$B != 0 DF$A != 0 & DF$B != 0 DF$A != 0 | DF$B != 0
1 0 0     FALSE     FALSE                 FALSE                 FALSE
2 1 0      TRUE     FALSE                 FALSE                  TRUE
3 0 1     FALSE      TRUE                 FALSE                  TRUE
4 1 1      TRUE      TRUE                  TRUE                  TRUE

Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Neil Shephard
Verzonden: maandag 25 februari 2008 15:36
Aan: ONKELINX, Thierry
CC: r-help
Onderwerp: Re: [R] Logical statements and subseting data...

Thanks Thierry, they do both leave me with what I expected.

On Mon, Feb 25, 2008 at 2:28 PM, ONKELINX, Thierry
<Thierry.ONKELINX op inbo.be> wrote:
> The negation of Height.1 == 0 & Height.2 == 0 was incorrect. Use
>
>  subset(raw.all.clean, !(Height.1 == 0 & Height.2 == 0))

I can see clearly how this expression works (negating the whole test),
but...

>  or
>
>  subset(raw.all.clean, Height.1 != 0 | Height.2 != 0)

...not how this works, since the above to me is saying Height.1 is NOT
zero OR  Height.2 is NOT zero, which to my mind would pick out samples
where either one or the other is not equal to zero (and of course
those instances where both are equal to zero)?

It seems to me that & (AND) and | (OR) are used the wrong way round in
this case, since the intersection of the two tests for inequality is
what is required?

Neil
-- 
Email - nshephard op gmail.com / n.shephard op sheffield.ac.uk

______________________________________________
R-help op 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