Re: [R] Logical statements and subseting data...

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Mon, 25 Feb 2008 15:59:15 +0100

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_at_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_at_r-project.org [mailto:r-help-bounces_at_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_at_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_at_gmail.com / n.shephard_at_sheffield.ac.uk

______________________________________________
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.

______________________________________________
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.
Received on Mon 25 Feb 2008 - 15:00:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Feb 2008 - 15:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive