[Rd] by "infelicity"
p.dalgaard at biostat.ku.dk
Thu Apr 3 14:16:26 CEST 2008
Tobias Verbeke wrote:
> Dear list,
> Please find below an example of odd
> behaviour of the by function.
> It occurs both under GNU/Linux R 2.6.2
> and Windows R 2.7.0alpha. Respective
> sessionInfo()'s are given below.
> I hope I do not overlook anything.
> testFactor <- factor(sample(LETTERS[1:6], size = 42, replace = TRUE))
> testMatrix <- matrix(rnorm(42 * 6), nrow = 42)
> testDf <- as.data.frame(testMatrix)
> by(data = testDf, INDICES = testFactor, FUN = mean) # OK
> by(data = testDf, INDICES = testFactor, FUN = median) # error
> # Error in median.default(data[x, ], ...) : need numeric data
The infelicity (if any) is not in by(). Try
The FUN in by() is applied to the subsetted data frame, and there is no
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel