【发布时间】:2019-11-25 19:44:38
【问题描述】:
我想在 tibble 中排列行,以便其中包含“Gas”的值位于 tibble 的底部。
这是我的数据:
library(dplyr)
df1 <- tibble(
col1 = c("ZBottom Gas","Almost Bottom Gas","Top","Bottom Gas", "Top"),
col2 = c(5, 7, 4, 8,6))
这是我希望数据的样子:
df1 <- tibble(
col1 = c("Top", "Top", "ZBottom Gas","Almost Bottom Gas","Bottom Gas"),
col2 = c(4, 6, 5, 7, 8))
我知道我可以将一个新变量分配给任何气体,其值为“2”,然后将其他所有内容分配给“1”,然后像这样使用:
df2 <- tibble(
col1 = c("ZBottom Gas","Almost Bottom Gas","Top","Bottom Gas", "Top"),
col2 = c(5, 7, 4, 8,6),
arrange = c(2,2,1,2,1))
df2 %>%
arrange(arrange) -> df3
这很好,但我只是想知道是否有更简单的方法来做到这一点?
谢谢
【问题讨论】: