[R] Swap variables in data.frame

Paul Smith phhs80 at gmail.com
Mon Jun 2 13:35:23 CEST 2008


On Mon, Jun 2, 2008 at 11:59 AM, Blubbele <birgit.lemcke at systbot.uzh.ch> wrote:
>
> 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)]

The following works:

d <- data.frame(a=c(1,2),b=c(3,4))
d <- d[,c(2,1)]

Paul



More information about the R-help mailing list