Re: [R] Swap variables in data.frame

From: Blubbele <birgit.lemcke_at_systbot.uzh.ch>
Date: Mon, 02 Jun 2008 03:59:44 -0700 (PDT)

Thanks but it swaps in both cases only the data:

FemMal_88[c(61,62)]=FemMal_88[c(62,61)]

FemMal_88[,c(61,62)]=FemMal_88[,c(62,61)]

Greets

B.

Karl Ove Hufthammer-4 wrote:
>
> Birgit Lemcke:
>

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

>
> To swap column 1 and 2, try
>
> d[c(1,2)]=d[c(2,1)]
>
> Note that this is different from
>
> d[,c(1,2)]=d[,c(2,1)]
>
> which will swap the data, but not the column names.
>
> --
> Karl Ove Hufthammer
>
> ______________________________________________
> 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.
>
>
-- 
View this message in context: http://www.nabble.com/Swap-variables-in-data.frame-tp17597476p17598708.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 Mon 02 Jun 2008 - 11:04:20 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 Mon 02 Jun 2008 - 12: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