[Rd] inconsistent behavior for logical vectors when using apply (" TRUE")

Adrian Dragulescu adrian_d at eskimo.com
Wed Nov 4 20:44:34 CET 2009


Hello,

> X <- data.frame(letters=letters[1:3], flag=c(TRUE, FALSE, TRUE))
> X
   letters  flag
1       a  TRUE
2       b FALSE
3       c  TRUE
> apply(X, 1, as.list)
[[1]]
[[1]]$letters
[1] "a"

[[1]]$flag
[1] " TRUE"


[[2]]
[[2]]$letters
[1] "b"

[[2]]$flag
[1] "FALSE"


[[3]]
[[3]]$letters
[1] "c"

[[3]]$flag
[1] " TRUE"

Notice how TRUE becomes " TRUE" and FALSE becomes "FALSE".  Not sure why 
TRUE gets an extra whitespace in front.

Checked with R-2.10.0, but can reproduce the behavior as far back as 
R-2.8.1.

Adrian Dragulescu

> sessionInfo()
R version 2.10.0 (2009-10-26)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United 
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.10.0



More information about the R-devel mailing list