Re: [R] Re order variables in a dataframe

2009-05-21 Thread Peter Dalgaard
Simon Blomberg wrote: How about to insert a variable a2 inbetween the first and second columns of dat: dat2 - cbind(dat[,1], a2=a2, dat[,2:3]) Where a2 is the new variable. This mangles the variable name for column 1, unfortunately. Surely someone else will offer a better solution. Simon.

Re: [R] Re order variables in a dataframe

2009-05-21 Thread pgseye
Thanks everyone -- View this message in context: http://www.nabble.com/Reorder-variables-in-a-dataframe-tp23647222p23660941.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

[R] Re order variables in a dataframe

2009-05-20 Thread pgseye
This is no doubt a very basic question for most R users, but is there an easy way to reorder the variables (columns) in a dataframe (I can't seem to find an answer anywhere). I've generally been creating a new dataframe and selecting the new order I want from the old but this is time-consuming.

Re: [R] Re order variables in a dataframe

2009-05-20 Thread Simon Blomberg
Alphabetically, like this?: dat - data.frame(d=rnorm(3), c=rnorm(3), b=rnorm(3), a=rnorm(3)) dat d c b a 1 -0.1816733 -0.4106008 -0.2855991 -1.022951 2 -1.8326818 -0.6515208 0.3344884 -2.191836 3 1.0924867 0.1159611 -1.3409719 1.195545 dat2 -

Re: [R] Re order variables in a dataframe

2009-05-20 Thread pgseye
Thanks Simon, I should have explained myself better (although I didn't know about the order function so that's handy information). I've found a few times, I've added variables to a dataframe that I would like to 'group' with variables earlier in the datset. So I was wondering if you could

Re: [R] Re order variables in a dataframe

2009-05-20 Thread Simon Blomberg
How about to insert a variable a2 inbetween the first and second columns of dat: dat2 - cbind(dat[,1], a2=a2, dat[,2:3]) Where a2 is the new variable. This mangles the variable name for column 1, unfortunately. Surely someone else will offer a better solution. Simon. On Wed, 2009-05-20 at

Re: [R] Re order variables in a dataframe

2009-05-20 Thread milton ruser
Following Simon's example dat - data.frame(d=rnorm(3), c=rnorm(3), b=rnorm(3), a=rnorm(3)) dat dat-subset(dat, select=c(d,a,b,c)) dat Bests milton brazil=toronto On Thu, May 21, 2009 at 12:02 AM, Simon Blomberg s.blombe...@uq.edu.auwrote: How about to insert a variable a2 inbetween the first