[R] strange behaviour of median

Petr PIKAL petr.pikal at precheza.cz
Thu Feb 4 10:11:56 CET 2010


Hi

Sorry, as many Windows users I forgot to mention version and platform

> version
               _  
platform       i386-pc-mingw32  
arch           i386  
os             mingw32  
system         i386, mingw32  
status         Under development (unstable)  
major          2  
minor          11.0  
year           2009  
month          10  
day            10  
svn rev        50027  
language       R  
version.string R version 2.11.0 Under development (unstable) (2009-10-10 
r50027)
> 

In R 2.9.0 I got the same result as you, in R2.10.0 I got same result as 
with R2.11.0dev In meantame I try latest R binary.

Regards
Petr

Mario Valle <mvalle at cscs.ch> napsal dne 04.02.2010 09:59:59:

> 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