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@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.

Reply via email to