[R] hiccup in apply?

From: bogdan romocea <br44114_at_gmail.com>
Date: Fri 19 Jan 2007 - 16:36:56 GMT


Hello, I don't understand the behavior of apply() on the data frame below.

test <-
structure(list(Date = structure(c(13361, 13361, 13361, 13361,

13361, 13361, 13361, 13361, 13362, 13362, 13362, 13362, 13362,
13362, 13362, 13362, 13363, 13363, 13363, 13363, 13363, 13363,
13363, 13363, 13364, 13364, 13364, 13364, 13364, 13364, 13364,
13364, 13365, 13365, 13365, 13365, 13365, 13365, 13365, 13365,
13366, 13366, 13366, 13366, 13366, 13366, 13366, 13366, 13367,
13367), class = "Date"), RANK = as.integer(c(19, 7, 5, 4, 6,
3, 3, 4, 18, 7, 6, 4, 6, 3, 3, 4, 19, 7, 6, 4, 6, 3, 3, 4, 18,
6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6,
3, 3, 4, 18, 6))), .Names = c("Date", "RANK"), row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
"47", "48", "49", "50"), class = "data.frame")

#---fine
> summary(test)

      Date                 RANK
 Min.   :2006-08-01   Min.   : 3.00
 1st Qu.:2006-08-02   1st Qu.: 4.00
 Median :2006-08-04   Median : 5.50
 Mean   :2006-08-03   Mean   : 6.62

 3rd Qu.:2006-08-05 3rd Qu.: 6.75
 Max. :2006-08-07 Max. :19.00

#---isn't this supposed to work?
> apply(test,2,mean)

Date RANK
  NA NA
Warning messages:
1: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...)
2: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...)

Thank you,
b.

platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          2
minor          4.0
year           2006
month          10
day            03
svn rev        39566
language       R

version.string R version 2.4.0 (2006-10-03)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Jan 20 03:56:24 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 19 Jan 2007 - 18:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.