[英]Print ordered table in R
使用 df 像:
df <- tibble(dist = c(x,x,y,x,y), desc = c("txt","txt2","txt3","txt4,"txt5"), count = c(20,10,5,30,10))
如何為一個dist
打印一個表,按count
排序:
desc count
txt4 30
txt1 20
txt2 10
使用dplyr
:
library(dplyr)
df %>% filter(dist == 'x') %>% arrange(desc(count)) %>% select(-dist)
# desc count
# <chr> <dbl>
#1 txt4 30
#2 txt1 20
#3 txt2 10
或者在基數 R 中:
temp <- subset(df, dist == 'x', select = -dist)
temp[order(-temp$count), ]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.