That is strange. Thanks for pointing that out--that's something that
would be hard to debug.
The simplest hack around that is just to use is.na() or is.integer.
nrow(X[X[,1]==TRUE & !is.na(X),])
Also strange to notice that it looks like R is very eager to force
Booleans into integers
c(TRUE, 7)
[1] 1 7
I have no idea what this would do.
/\llan
On Sat, 20 Nov 2004 16:09:50 -0500, Andrew Eggers <aeggers(a)gmail.com> wrote:
I discovered an unpleasant R feature and wondered if
anyone could
suggest a workaround or show me where I am going wrong.
I have been using logical statements and nrow() to extract the number
of observations that have certain characteristics.
for example, I thought the following statement
nrow(X[X[,1]==TRUE,])
would tell me how many rows of X had TRUE in the first column.
But it turns out that R considers anything that is TRUE or 1 _or_ NA
as TRUE. (The same is true when you say nrow(X[X[,1]==1,]).)
Can anyone tell me how to deal with this? Can anyone explain why R
would count NA as TRUE?
Andy
_______________________________________________
gov2001-l mailing list
gov2001-l(a)lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l