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]]
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 2specific 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, thecolumn with the lowest mean, and column 4, the column with the highest mean> > thanks, > > Andras > [[alternative HTML version deleted]] >- - - - - Boycott Apple!
Hi, Try this: ?which.min(apply(a,2,mean)) #[1] 1 ?which.max(apply(a,2,mean)) #[1] 4 A.K. ----- Original Message ----- From: Andras Farkas <motyocska at yahoo.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Sunday, September 2, 2012 5:49 AM Subject: [R] Help on finding specific columns in matrix 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]] ______________________________________________ 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.
HI Andras, No problem.? But, i guess using colMeans() as suggested by Rainer should be faster in large datasets. A.K. ----- Original Message ----- From: Andras Farkas <motyocska at yahoo.com> To: smartpink111 at yahoo.com Cc: Sent: Sunday, September 2, 2012 4:59 PM Subject: Re: [R] Help on finding specific columns in matrix this works nicely, thanks arun... Andras ------------------------------ On Sun, Sep 2, 2012 11:50 AM EDT arun wrote:>Hi, >Try this: >?which.min(apply(a,2,mean)) >#[1] 1 >?which.max(apply(a,2,mean)) >#[1] 4 >A.K. > > > > >----- Original Message ----- >From: Andras Farkas <motyocska at yahoo.com> >To: "r-help at r-project.org" <r-help at r-project.org> >Cc: >Sent: Sunday, September 2, 2012 5:49 AM >Subject: [R] Help on finding specific columns in? matrix > >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]] > > >______________________________________________ >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. >