【发布时间】:2018-07-21 07:58:25
【问题描述】:
Col1 Col2 Col3
Row1 Pink rose Red Apple Blue Cage
Row2 Pink rose Red Apple Blue Cage
Row3 Pink rose Blue Cage Red Apple
Row4 Pink rose Red Apple Blue Cage
Row5 Pink rose Blue Cage Red Apple
在 R 中,您将如何交换“红苹果”和“蓝笼”的位置,以便它们位于各自的列中。
例如。将 Col2, Row4 'Red Apple' 与 Col3, Row4 'Blue Cage' 交换
提前谢谢你。
【问题讨论】:
-
df$Col2 = "Red Apple"?这有帮助吗? -
感谢这绝对有效!但是,我更多的是指交换单元格。例如。将 Col2, Row4 'Red Apple' 与 Col3, Row4 'Blue Cage' 交换。谢谢
-
您是否只是想交换两列?喜欢
df[c("Col2","Col3")] <- df[c("Col3","Col2")]