[Rd] by

Tobias Verbeke tobias.verbeke at telenet.be
Thu Apr 3 14:29:59 CEST 2008


>----- Oorspronkelijk bericht -----
>Van: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk]
>Verzonden: donderdag, april 3, 2008 02:16 PM
>Aan: 'Tobias Verbeke'
>CC: r-devel at r-project.org
>Onderwerp: Re: [Rd] by "infelicity"
>
>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.

Apologies. Thanks for the clarification.

Kind regards,
Tobias



More information about the R-devel mailing list