Hello everyone, I have a matrix of over 40000 line and about 30 columns. For my analysis I would like to add another column with ascending numbers (column header should be "order", and than 1,2,3,4 ....the end of the matrix). During my analysis I reorder them ( due to merge commands by a different column). How do I add such a column in an ascending order (or descending for what it matters)? THX Assa [[alternative HTML version deleted]]
Hi r-help-bounces at r-project.org napsal dne 10.06.2010 15:56:06:> Hello everyone, > > I have a matrix of over 40000 line and about 30 columns.Matrix or data.frame?> > For my analysis I would like to add another column with ascendingnumbers> (column header should be "order", and than 1,2,3,4 ....the end of the > matrix).If data frame DF DF$order <- 1:nrow(DF) in case of matrix mat mat <- cbind(mat, "order"=1:nrow(mat)) Regards Petr PS. order is built in function so it is not especially wise to use it as a name for some object/column> During my analysis I reorder them ( due to merge commands by a different > column). > > How do I add such a column in an ascending order (or descending for whatit> matters)? > > THX > > Assa > > [[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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
> newmat <- cbind( oldmat, order=seq(nrow(oldmat)) )See ?seq and/or ?rev for descending. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Assa Yeroslaviz > Sent: Thursday, June 10, 2010 7:56 AM > To: r-help at stat.math.ethz.ch > Subject: [R] adding column of ordered numbers to matrix > > Hello everyone, > > I have a matrix of over 40000 line and about 30 columns. > > For my analysis I would like to add another column with ascending > numbers > (column header should be "order", and than 1,2,3,4 ....the end of the > matrix). > During my analysis I reorder them ( due to merge commands by a > different > column). > > How do I add such a column in an ascending order (or descending for > what it > matters)? > > THX > > Assa > > [[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.