[R] sapply and median, possible or not ?

Keith Jewell k.jewell at campden.co.uk
Fri Nov 7 12:55:19 CET 2008


I haven't looked at the detail, but I guess the answer is that mean works on 
a data frame while median doesn't.
--------
?mean
<snip>
For a data frame, a named vector with the appropriate method being applied 
column by column.
---------

I guess to use median you'll need nested '[l/s]apply's, the outer working 
through the list of dataframes and the inner working through the columns of 
each dataframe.

Or perhaps, by analogy with mean.data.frame you could just define
---------
median.data.frame <- function(x, ...)
sapply(x, median, ...)
------------

I haven't tried it, but it might work

hth

Keith J
-----------------
"Ptit_Bleu" <ptit_bleu at yahoo.fr> wrote in message 
news:20378663.post at talk.nabble.com...
>
> Unfortunately, I have the same error message.
> lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not
> with median.
> Strange, isn't it?
>
> Any other idea?
>
> Thanks in advance,
> Ptit Bleu.
>
>
> Henrique Dallazuanna wrote:
>>
>> Try this:
>>
>> lapply(l, function(x)median(x[,sapply(x, is.numeric)]))
>>
>>
>> -- 
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>> [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>
>>
>
> -- 
> View this message in context: 
> http://www.nabble.com/sapply-and-median%2C-possible-or-not---tp20378222p20378663.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>



More information about the R-help mailing list