baz baz - 3 months ago 12
R Question

Is it possible to swap columns around in a data frame using R?

I have three variables in a data frame and would like to swap the 4 columns around from

"dam" "piglet" "fdate" "ssire"


to

"piglet" "ssire" "dam" "tdate"


Is there any way I can do the swapping using R?

Any help would be very much appreciated.

Baz

42- 42-
Answer
dfrm <- dfrm[c("piglet", "ssire", "dam", "tdate")]

OR:

dfrm <- dfrm[ , c("piglet", "ssire", "dam", "tdate")]