Note that there is a confusion here: 1st dimension is row, 2nd dimension
is column for matrix & data.frame.
So, if the question is about "rowMedian", you have:
> rowMedian <- function(x, na.rm = FALSE)
> apply(x, 2, median, na.rm = na.rm)
Now, you ask for the "median for specified columns", which should be
as
Andy proposes you, or, if you really want a colMedian function:
> colMedian <- function(x, na.rm = FALSE)
> apply(x, 1, median, na.rm = na.rm)
Best,
Philippe Grosjean
Liaw, Andy wrote:> apply(x, 1, median) should do it. If not, you need to explain why.
>
> Andy
>
> -----Original Message-----
> From: Max Kauer
> Sent: Friday, January 20, 2006 10:24 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] function for rowMedian?
>
>
> Hi
> is anybody aware of a function to calculate a the median for specified
> columns in a dataframe or matrix - so analogous to rowMeans?
> Thanks
> Max
>
> --
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>