[R] Summary statistics for matrix columns

Pete Brecknock Peter.Brecknock at bp.com
Fri Nov 23 02:44:58 CET 2012


frespider wrote
> Hi,
> 
> is there a way I can calculate a summary statistics for a columns matrix
>  let say we have this matrix 
> x <- matrix(sample(1:8000),nrow=100)
> colnames(x)<- paste("Col",1:ncol(x),sep="")
> 
> if I used summary 
> summary(x) 
> 
> i get the output for each column but I need the output to be in matrix
> with rownames  and all the columns beside it 
> 
> this how I want it 
> 
>                 Col76     Col77
>  Min.      :    7            39  
>  1st Qu. :    1846   1630   
>  Median :   3631   3376   
>  Mean    :   3804   3617 
> Sd          :   
>  3rd Qu.:    5772   5544  
> IQR        :
>  Max.   :    7952    7779  
> 
> Is there an easy way?
> 
> Thanks

How about ...

x <- matrix(sample(1:8000),nrow=100)
colnames(x)<- paste("Col",1:ncol(x),sep="")

apply(x,2,function(x) c(summary(x), sd=sd(x), IQR=IQR(x)))

HTH

Pete



--
View this message in context: http://r.789695.n4.nabble.com/Summary-statistics-for-matrix-columns-tp4650489p4650490.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list