[R] Odp: Moving a Data Frame Column

Petr PIKAL petr.pikal at precheza.cz
Thu Jan 15 09:50:49 CET 2009


Hi

r-help-bounces at r-project.org napsal dne 15.01.2009 04:47:39:

> 
> Dear R-Users
> if I have a data frame (or zoo data) as follows:
> 
> Run  Bike Walk Drive
> 1       2      7     5
> 5       2      4     2 
> 8       3      2     1
> 
> How can I re-order it so that it reads: 
> 
> Drive Run  Bike Walk 
>   5      1      2     7 
>   2      5      2     4 
>   1      8      3     2 
> i.e. "Drive" has been copied and pasted to the left most column.

> test
  Run Bike Walk Drive
1   1    2    7     5
2   5    2    4     2
3   8    3    2     1

test2 <- test[, c(4,1,2,3)]
  Drive Run Bike Walk
1     5   1    2    7
2     2   5    2    4
3     1   8    3    2

if you want it in new data frame or

test <- test[, c(4,1,2,3)]

if you want to overwrite it.

Regards
Petr


> 
> Thanks for your help.
> 
> James
> -- 
> View this message in context: http://www.nabble.com/Moving-a-Data-Frame-
> Column-tp21470798p21470798.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list