[R] Help on finding specific columns in matrix

Rainer Schuermann rainer.schuermann at gmx.net
Sun Sep 2 15:30:07 CEST 2012


If I understand your question correctly, you want to identify the one column 
that has the lowest mean of all columns, and the one column that has the 
highest mean of all columns.

Using your provided sample data, this gives you the indices:

> colMeans(a)
[1] 12.48160 17.46868 22.51761 27.59880
> which.min( colMeans( a ) ) 
[1] 1
> which.max( colMeans( a ) ) 
[1] 4

Does that help?

Rgds,
Rainer


On Sunday 02 September 2012 02:49:11 Andras Farkas wrote:
> Dear All,
>  
> I have a matrix with 33 columns and 5000 rows. I would like to find 2 
specific columns in the set: the one that holds the highest values and the one 
that holds the lowest values. In this case the column's mean would be 
apropriate to use to try to find those specific columns because each columns 
mean is different and they all change together based on the same "change of 
rate constants" as a function of time (ie: tme is the most important 
determinant of the magnitude of that mean).  The columns are not to be named, 
if possible.... Any thoughts on that? Would apreciate the help....
>  
> example:
>  
> a <-
matrix(c(runif(500,10,15),runif(500,15,20),runif(500,20,25),runif(500,25,30)),ncol=4)
>  
> I would need to find and plot with a box percentile plot column 1, the 
column with the lowest mean, and column 4, the column with the highest mean
>  
> thanks,
>  
> Andras 
> 	[[alternative HTML version deleted]]
> 






- - - - -

Boycott Apple!




More information about the R-help mailing list