Skip to content
Prev 324254 / 398503 Next

How I can rearrange columns in data.frame?

On 27-05-2013, at 20:17, Kristi Glover <kristi.glover at hotmail.com> wrote:

            
dat2 <- dat[,c("preV15A1b", "preV59A1b", "preV1001A1b", "preV2032A1b", "preV2035A1b")]
identical(dat1,dat2)   

or something like this:

dat3.cols <- match(c("preV15A1b", "preV59A1b", "preV1001A1b", "preV2032A1b", "preV2035A1b"), names(dat))
dat3 <- dat[,dat3.cols]
identical(dat3,dat2)

A general solution will depend on the new ordering of your columns.

Berend