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

Peter Dalgaard pdalgd at gmail.com
Sun Aug 15 22:56:04 CEST 2010


David Winsemius wrote:
> 

>>
> 
> What about changing it to behave thusly:
> 
>  > as.logical.factor <- function(vec)  
> as.logical(as.numeric(factor(vec))-1 )
> 
>  > as.logical(as.numeric(factor(c("TRUE", "FALSE", NA)))-1 )
> [1]  TRUE FALSE    NA
>  > as.logical(as.numeric(factor(c(TRUE, FALSE, NA)))-1 )
> [1]  TRUE FALSE    NA
> 
> 

No way: Think

factor(dead, levels=c(1, 2), labels=c("TRUE", "FALSE"))

(People are not _that_ unlikely do that. E.g., the tradition in
epidemiology is to label tables with +/- in that order.)

Anyways, Brian points out (privately) that it used to work as documented
prior to v.2.6.0, so there's not likely to be that much of a problem
with reinstating that behaviour.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list