[R] strange behaviour of median

Petr PIKAL petr.pikal at precheza.cz
Thu Feb 4 09:32:15 CET 2010


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



More information about the R-help mailing list