[R] ?Bug: '&&' and '&' give different results?

From: <andreas_at_jostel.com>
Date: Mon 02 Apr 2007 - 07:17:46 GMT


"&&" seems to behave strangely and gives different results from "&" e.g. in a data frame selection (regardless whether terms are bracketed)?

===========Script=======================

test=data.frame(gender=c("F","M","M","F","F"),side=c("R","L","R","L","R")) test
test[test$gender=="F" & test$side=="R",] test[test$gender=="F" && test$side=="R",]

=============Output:=====================

> test=data.frame(gender=c("F","M","M","F","F"),side=c("R","L","R","L","R"))
> test

  gender side
1      F    R
2      M    L
3      M    R
4      F    L
5      F    R

> test[test$gender=="F" & test$side=="R",]
  gender side
1      F    R
5      F    R

> test[test$gender=="F" && test$side=="R",]
  gender side
1      F    R
2      M    L
3      M    R
4      F    L
5      F    R

______________________________________________
R-help@stat.math.ethz.ch 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 Apr 02 17:22:35 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 02 Apr 2007 - 08:30:36 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.