- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
给定一个数据集,我们可以使用 top_n
来限制我们在 tidyverse
中返回的行数(即排序/排名)。我喜欢大多数 tidyverse
操作的灵活性,因为它们在大多数情况下可以撤消,即您可以回到开始的地方。
使用这里问题中的数据和可能的解决方案(我写的),我怎样才能最好地撤消 top_n
?
数据 :
df<-structure(list(milk = c(1L, 2L, 1L, 0L, 4L), bread = c(4L, 5L,
2L, 1L, 10L), juice = c(3L, 4L, 6L, 5L, 2L), honey = c(1L, 2L,
0L, 3L, 1L), eggs = c(4L, 4L, 7L, 3L, 5L), beef = c(2L, 3L, 0L,
1L, 8L)), class = "data.frame", row.names = c(NA, -5L))
df %>%
gather(key,value) %>%
group_by(key) %>%
summarise(Sum=sum(value)) %>%
arrange(desc(Sum)) %>%
top_n(3,Sum) %>%
ungroup()
# A tibble: 3 x 2
key Sum
<chr> <int>
1 eggs 23
2 bread 22
3 juice 20
top_n
恢复:
spreading
(
res
就是上面的结果):
spread(res,key,Sum)
# A tibble: 1 x 3
bread eggs juice
<int> <int> <int>
1 22 23 20
top_n
的替代解决方案着手(还)。我怎样才能最好地实现这一目标?
最佳答案
使用 pull
的类似想法,但方法略有不同:
library(tidyverse)
df %>%
summarise_all(sum) %>% # Your method of selecting
gather(key, val) %>% # top three columns
top_n(3) %>% #
arrange(-val) %>% #
pull(key) %>% # pull 'key'
select(df, .) # select cols from df by `.`
# eggs bread juice
#1 4 4 3
#2 4 5 4
#3 7 2 6
#4 3 1 5
#5 5 10 2
df[, '['(names(sort(colSums(df), T)), 1:3)]
关于返回top_n后的原始数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57230069/
在更大的应用程序的上下文中,我的小程序需要将一些数据打印到 Zebra 或 Dymo(取决于用户安装的内容)标签打印机。 我收到的数据是转义形式,我只需要发送到打印机并让它解释它的数据。 搜索我找到了
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭去年。 Improve th
我正在尝试使用 GetUserMedia() 从用户麦克风录制和保存声音片段和 AudioContext蜜蜂。 我已经能够使用 MediaRecorder 做到这一点API,但不幸的是,Safari/
我想编写一个将十六进制数据转换为音频文件的小型Web应用程序。 音频文件的数据将采用十六进制格式,如下所示: DA1FFFF8B3AEEE2E23BBB9A2221F10400180001EF1C1E
在其中一个 API 中,我收到以下 Json 响应:您可以在此处查看此响应示例 Sample Json resopnse { "histogram" : { "1" : "12
如何在 python 上使用 Resuests 库发布原始数据?我正在尝试登录。 Json 抛出异常 TypeError: set(['"clienteLogin":{"Token":"b94261f
有人告诉我,无论何时使用字节,都应该将变量声明为无符号字符。在 Windows 的数据类型中,BYTE 被声明为 unsigned char。 我的问题: 为什么? Unsigned 是从 0 到 2
如何读取 GPS 原始数据,更具体地说,我需要卫星伪距。此数据不提供 NMEA 格式。 最佳答案 卫星伪距在 official API 中不可用 ,既不通过 GpsStatus.Listener 也不
给定以下 XML: 1424 我正在尝试获取
我使用了以下代码将十进制的 bigint 转换为 bytearray(原始数据),但我得到了错误的结果。 这里有什么错误吗? 我正在 Apple Mac 中尝试此操作(适用于 Iphone 应用程序)
我在 iOS 应用程序中使用 Firebase 登录时遇到了表格 View 问题。该表从子提要加载内容。当我第一次登录时,表加载正常,但如果我注销并再次登录,表会重新加载所有数据,将原始数据添加到表的
我正在使用 Apache BCEL动态创建 java 类,每个类都有自己的关联图像。这些生成的类实现了以下接口(interface): interface ImageOwner { byte[
有没有办法读取 Sim 卡的“原始”数据?类似于如何使用 Pdu 的 SmsMessage 原始数据读取原始数据? 最佳答案 阅读SIM卡相关信息需要TelephonyManager API . Te
有没有办法在命令行 curl 中将数据 POST 或 GET(插入您最喜欢的 HTTP 方法)数据到 URL 并包含在原始发布的数据 header 值中,而不是发出 -H 选项? 例如: $curl
我正在开展一个项目,尝试使用 Myo Gesture Control Armband 识别一些用于康复治疗的 Action /姿势。 . 我有三个问题: EMG Raw Data 返回的最大值和最小值
我有 flv 文件,其中包含带有 aac 原始数据的音频标签。每个音频标签都有一组 aac 原始数据。原始数据有不同的大小。我想通过 RTP 发送。我添加了 13 位大小的 AU header 。它是
我使用制造商提供的库通过 USB 访问相机。我通过结构接收有关图像的信息: typedef struct { /*! Buffer handle which contains new data
我正在从事 BLE 项目,其中录音机硬件连续流式传输数据并发送到 iOS 应用程序。从 iOS 应用程序端,我需要读取传输的数据。 硬件向 iOS 应用程序发送 HEX 数据,我们需要创建 .mp3/
我正在尝试使用 AFNetworking 发出 HTTP PUT 请求以在 CouchDB 服务器中创建附件。服务器需要 HTTP 正文中的 base64 编码字符串。如何在不使用 AFNetwork
我有一些 Graylog2 使用 syslog 输入插件接收的日志。 我需要以我收到的相同格式导出它们,无需任何解析,以便我可以发送给应用程序支持团队。 我已将 INPUT 设置为保留 full_ma
我是一名优秀的程序员,十分优秀!