[R] ?Bug: '&&' and '&' give different results?
andreas at jostel.com
andreas at jostel.com
Mon Apr 2 09:17:46 CEST 2007
"&&" 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
More information about the R-help
mailing list