r - 在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), ]
推荐阅读
- javascript - 加载时的jquery窗口未执行
- javascript - Vuex获取循环ID到axios
- sql-server - 如何超链接 Azure Data Studio 中的值?
- java - 子窗口出现在主窗口的背景中?
- ios - SwiftUI 在 Picker 对象中显示图像
- pytorch - 将 Dataloader 数据移动到 GPU PyTorch
- ruby-on-rails - 找不到对应 JSONB 列的记录
- java - 为什么我的编辑文本没有过滤列表视图
- vue.js - 在 Vue 中创建物化吐司动作
- c++ - 使用 Opengl 函数时程序崩溃 (GLFW + GLAD)