将行移至表格

时间:2017-07-31 18:44:31

标签: r dataframe

我想知道是否可以从表格的底部到顶部移动一行。当我使用到目前为止的代码时,

dt[nrow(dt)+1,] <- rbind(c("","","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","1X","2X","6X","3X",""), dt)

table 使用此代码,我在表格的底部得到一个新行。如果我将“+1”更改为“-22”,则该行会转到table 2的顶部。如果我进行此更改,则会从表格底部删除一行。任何帮助,为什么会发生这种情况将不胜感激。

1 个答案:

答案 0 :(得分:4)

有几种方法,但这里有两种简单方法:

a <- data.frame(x = 1:10, y = 20:29)
a <- a[c(10,1:9),]
a

##Or

a <- data.frame(x = 1:10, y = 20:29)
a <- rbind(a[10,],a[1:9,])
a