是否可以使用 R 在数据框中交换列? [英] Is it possible to swap columns around in a data frame using R?

查看:30
本文介绍了是否可以使用 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"

有什么办法可以使用 R 进行交换吗?

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

非常感谢任何帮助.

巴兹

推荐答案

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

或:

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

这篇关于是否可以使用 R 在数据框中交换列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆