During some experimentation in preparing R lessons I encountered this 
behaviour which I can not explain fully

mat <- matrix(1:16, 4,4)
df1 <- data.frame(mat)

> mean(df1)
  X1   X2   X3   X4 
 2.5  6.5 10.5 14.5 

Expected, documented

> median(df1)
[1]  6.5 10.5

Rather weird, AFAIK there shall not be an issue with data frame at least I 
did not find any in help page. I tracked it down probably to an As.Is 
operation with object and subsequent sorting in median.default.

I know other (*apply) ways how to compute median for data frames so I just 
would like to hear an opinion about this behaviour from more experienced 
people.

Thank you
Best regards

Petr

______________________________________________
R-help@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.

Reply via email to