I was trying to identify columns in a data frame that contained all missing
values, and thought
to apply a function over its columns.
fjj <- data.frame(A = 1:5, B = rep(NA,5), C = logical(5), D = rep(NA, 5))
> fjj
A B C D
1 1 NA FALSE NA
2 2 NA FALSE NA
3 3 NA FALSE NA
4 4 NA FALSE NA
5 5 NA FALSE NA
> apply(fjj, 2, function(x) all(is.na(x)))
A B C D
F F F F
> sapply(fjj, function(x) all(is.na(x)))
A B C D
F T F T
Does anyone know why sapply works instead of apply (i.e., the difference
between them
as applied to data frames)? Thanks in advance.
Regards,
Greg Ciresi
gregciresi@aol.com
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|