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

From: Adrian Dragulescu <adrian_d_at_eskimo.com>
Date: Wed, 04 Nov 2009 11:44:34 -0800 (PST)

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 04 Nov 2009 - 19:46:23 GMT

This archive was generated by hypermail 2.2.0 : Wed 11 Nov 2009 - 15:50:23 GMT