baz baz - 1 year ago 47
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"


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

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

Any help would be very much appreciated.


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


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