TRUE and FALSE are reserved words in R. I do not think eznme was right (before editing it) when he said that any nonzero value was TRUE, since TRUE == "A" evaluates to FALSE. (It would be correct to explain why TRUE == 1 evaluates to TRUE, but does not explain the result for TRUE == 7
The explanation given by plannapus has been inferred from the context of the as.logical behavior as.logical . It is closer to true because it implicitly forces TRUE to a character using the == operator, which creates this result. Although T and F initially set to TRUE and FALSE, they can be reassigned to other values ββor types.
> TRUE == as.logical( c("TRUE", "T", "true", "True") ) [1] TRUE TRUE TRUE TRUE > TRUE == 7 [1] FALSE > TRUE == as.logical(7) [1] TRUE > TRUE == as.logical("A") [1] NA
(Earlier, I wrote incorrectly that coercion induced by TRUE == "TRUE" was logical: in fact, as.character (TRUE) returns "TRUE".)
February 42-18 '13 at 8:40 2013-02-18 08:40
source share