Flextable 或 dplyr R - 更改行顺序

问题描述 投票:0回答:1

请告知如何控制弹性表中的行顺序。

例如,在表格流行病学家R手册中,行的顺序按升序排列,其他行和缺失行位于表格中间。但我想最后得到这些行。如何做到这一点?

https://epirhandbook.com/en/tables-for-presentation.html

enter image description here

我预计表中的行顺序将如下所示:

中心医院 军队医院 港口医院 圣马可妇产医院 (SMMH) 其他 丢失的 总计

r dplyr row flextable
1个回答
0
投票

最简单的方法是更改此列的索引:

ids=which(df$Hospital %in%c('其他', '失踪', '总计')

df2=df[ids,]

df=df[-c(ids),]

df=rbind(df,df2)

© www.soinside.com 2019 - 2024. All rights reserved.