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

后端 未结 7 2010
野的像风
野的像风 2020-12-08 19:54

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

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

to

7条回答
  •  温柔的废话
    2020-12-08 20:20

    You can use subset's 'select' argument;

    #Assume df contains "dam" "piglet" "fdate" "ssire"
    
    newdf<-subset(df, select=c("piglet", "ssire", "dam", "tdate"))
    

提交回复
热议问题