[R] Swap variables in data.frame

Karl Ove Hufthammer Karl.Hufthammer at math.uib.no
Mon Jun 2 11:48:06 CEST 2008

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


Note that this is different from


which will swap the data, but not the column names.

Karl Ove Hufthammer

More information about the R-help mailing list