[R] sapply and median, possible or not ?
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.
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
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
"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
>> 25° 25' 40" S 49° 16' 22" O
>> [[alternative HTML version deleted]]
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help