From p.dalgaard at biostat.ku.dk  Thu Apr  3 14:16:26 2008
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Thu, 03 Apr 2008 14:16:26 +0200
Subject: [Rd] by "infelicity"
In-Reply-To: <W2229325762230231207222956@nocme1bl6.telenet-ops.be>
References: <W2229325762230231207222956@nocme1bl6.telenet-ops.be>
Message-ID: <47F4CA9A.407@biostat.ku.dk>

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

mean(airquality)
median(airquality)

The FUN in by() is applied to the subsetted data frame, and there is no 
median.data.frame method.

-- 
   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



[Rd] by "infelicity"
Peter Dalgaard