[R] Reordering the columns of my dataframe
Rolf Turner
r.turner at auckland.ac.nz
Mon Jul 27 23:51:39 CEST 2009
On 28/07/2009, at 9:45 AM, Mark Na wrote:
> Hi R-helpers,
>
> I have written this line of code:
>
>> data<-cbind(data[,1],data[,2:6],data[,18],data[,7:17])
>
> to reorder the columns of my dataframe, but I'm losing the column
> names of
> my 1st and 18th columns (they are now named data[,1] and data[,18]
> respectively).
>
> Can I use cbind to do this (without losing my column names) or is
> there
> another way?
Just do
data <- data[,c(1:6,18,7:17)]
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list