Re: [R] Swap variables in data.frame

From: Birgitle <birgit.lemcke_at_systbot.uzh.ch>
Date: Tue, 03 Jun 2008 08:25:26 -0700 (PDT)

Thanks might be easier in my case because I have so many variables. Could have found this solution on my own.

Birgit

Rogers, James A [PGRD Groton] wrote:
>
>
> Birgit Lemcke wrote:
>

>> I have a dataframe and two of my variables are in the wrong position 
>> and I would like to swap those variables. 

>
> In addition to the other solutions posted, if you prefer to reference
> the columns by name rather than by index, you could use subset()
>
> dat <- data.frame(a = letters[1:3], b = LETTERS[1:3], c = 1:3, d = 3:1)
>
> subset(dat, select = c(b, a, c, d))
> ## or equivalently, something like:
> subset(dat, select = c(b:a, c:d))
>
>
> --Jim
>
> James A. Rogers, Ph.D.
> Associate Director, Neuroscience Statistics
> Pfizer Global R&D New London
> 50 Pequot Avenue (MS 6025-B2131)
> New London, CT 06320
> office: (860) 732-0783
> cell: (860) 501-7228
> fax: (860) 686-7866
>
>
>
> ______________________________________________
> 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.
>
>


The art of living is more like wrestling than dancing. (Marcus Aurelius)
-- 
View this message in context: http://www.nabble.com/Swap-variables-in-data.frame-tp17597476p17626237.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.
Received on Tue 03 Jun 2008 - 17:59:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jun 2008 - 18:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive