[R] Why do data frame column types vary across apply, lapply?
Jeff Brown
dopethatwantscash at yahoo.com
Fri Apr 30 17:08:36 CEST 2010
Hi,
I still have little ability to predict how these functions will treat the
columns of data frames:
> # Here's a data frame with a column "a" of integers,
> # and a column "b" of characters:
> df <- data.frame(
+ a = 1:2,
+ b = c("a","b")
+ )
> df
a b
1 1 a
2 2 b
>
> # Except -- both columns are characters:
> apply (df, 2, typeof)
a b
"character" "character"
>
> # Except -- they're both integers:
> lapply (df, typeof)
$a
[1] "integer"
$b
[1] "integer"
>
> # Except -- only one of those integers is numeric:
> lapply (df, is.numeric)
$a
[1] TRUE
$b
[1] FALSE
Many thanks,
Jeff
--
View this message in context: http://r.789695.n4.nabble.com/Why-do-data-frame-column-types-vary-across-apply-lapply-tp2077054p2077054.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list