[R] strange behaviour of median

Mario Valle mvalle at cscs.ch
Thu Feb 4 09:59:59 CET 2010


Linux 2.9.0 gives:

> median(df1)
[1] 34

Ever stranger...
		mario

Petr PIKAL wrote:
> 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 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.

-- 
Ing. Mario Valle
Data Analysis and Visualization Group            | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82



More information about the R-help mailing list