[R] as.logical(factor) behaviour

2010-08-15 Thread Philippe Grosjean
Hello, According to ?as.logical: as.logical attempts to coerce its argument to be of logical type. For factors, this uses the levels (labels). However, as.logical(factor(c(FALSE, TRUE))) [1] TRUE TRUE Shouldn't it be the same as: as.logical(levels(factor(c(FALSE, TRUE [1] FALSE

Re: [R] as.logical(factor) behaviour

2010-08-15 Thread R Help
The problem is that, underneath the factors are actually numbers (1 and 2), where as, if you extract the levels and then get the logical, it converts them to strings and then to logicals. I run into this problem ALL THE TIME with numerics in a dataset. Consider the following:

Re: [R] as.logical(factor) behaviour

2010-08-15 Thread Philippe Grosjean
Thank you, but I already know that. I am not surprised by this behavior, but by an inconsistency between that behavior and the documentation that says For factors, this uses the levels (labels)., which it does not. Best, Philippe On 15/08/10 16:09, R Help wrote: The problem is that,

Re: [R] as.logical(factor) behaviour

2010-08-15 Thread Peter Dalgaard
Philippe Grosjean wrote: Thank you, but I already know that. I am not surprised by this behavior, but by an inconsistency between that behavior and the documentation that says For factors, this uses the levels (labels)., which it does not. Best, My gut feeling say that the docs need to be