[R] Change positions of columns in data frame

2009-10-23 Thread Joel Fürstenberg-Hägg
Hi all, Probably a simple question, but I just can't find a simple answear in the older threads or anywhere else. I've added some new vectors as columns in a data frame using cbind(). As they're all put as the last columns inte the data frame, I would like to move them to specific positions.

Re: [R] Change positions of columns in data frame

2009-10-23 Thread John Kane
dataframe xx x1 x2 x3 1 2 5 2 4 1 5 6 0 1 1 2 data.frame(xx$x2,xx$x1,xx$x3) # or Awkward but works --- On Fri, 10/23/09, Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com wrote: From: Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com Subject: [R] Change positions

Re: [R] Change positions of columns in data frame

2009-10-23 Thread Peter Ehlers
DF[ ,names(DF)[c(your_preferred_order)]] -Peter Ehlers Joel Fürstenberg-Hägg wrote: Hi all, Probably a simple question, but I just can't find a simple answear in the older threads or anywhere else. I've added some new vectors as columns in a data frame using cbind(). As they're all put as

Re: [R] Change positions of columns in data frame

2009-10-23 Thread Phil Spector
Joel - Suppose the columns are named x1, x2, x3, x4, and x5. You can use subscripting: x[c('x2','x4','x1','x3','x5')] or, to save typing the quotes subset(x,select=c(x2,x4,x1,x3,x5)) - Phil Spector

Re: [R] Change positions of columns in data frame

2009-10-23 Thread Tom Gottfried
You can change the order of nearly everything just by applying an appropriate index and assigning to the original object. Something like data - data[,order_of_columns] Tom Joel Fürstenberg-Hägg schrieb: Hi all, Probably a simple question, but I just can't find a simple answear in the

Re: [R] Change positions of columns in data frame

2009-10-23 Thread Mark Na
Hi Joel, The answers you've received already, suggesting subscripting, are good because they strengthen your understanding of R subscripting. However, sometimes these methods produce strange column names. So, what I usually do is use the subset command. You don't have to provide anything for the