[英]can i apply filter in summarise_all?
I am doing sum up for my data frame. 我正在为我的数据框做总结。 My data frame looks like this:
我的数据框如下所示:
A B C D E F
1 1 1 1 4 2
2 2 5 6 9 9
3 1 7 1 2 4
4 9 6 5 6 6
5 4 7 9 1 5
6 9 9 7 5 7
7 6 1 6 7 8
8 8 3 4 3 6
9 9 4 6 1 1
I would love to sum up for each column, based on Link type. 我很想总结基于链接类型的每一列。 I can make it work with code:
我可以使用代码:
df>-datafram%>%
summaries_all(sum,na.rm=TRUE)
And the output is : 输出是:
A B C D E F
45 49 43 45 38 48
but when I apply with filter: 但是当我申请过滤器时:
summaries_all(sum(B<9),na.rm=TRUE),
the R said: R说:
Error in is_fun_list(.funs) : object 'B' not found
I would love to apply filter to my summaries_all so that only sum all the numbers that b<9 我很乐意将过滤器应用于我的summaries_all,以便只将b <9的所有数字相加
Can you guys give me some hints please 请你们给我一些提示
Many thanks 非常感谢
We can create a logical expression with 'B' to subset the values of each column and then do the sum
我们可以创建一个带有'B'的逻辑表达式来对每列的值进行子集化,然后进行
sum
library(dplyr)
datafram %>%
summarise_at(vars(-B), ~ sum(.[B < 9], na.rm = TRUE))
# A C D E F
#1 26 24 27 26 34
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.