Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 总结每个作品,但总结所有作品';T_R_Dplyr - Fatal编程技术网

R 总结每个作品,但总结所有作品';T

R 总结每个作品,但总结所有作品';T,r,dplyr,R,Dplyr,我正在dplyr中使用summary_all函数 当我使用不推荐的版本时,“每个汇总”效果很好,但当我汇总所有内容时,我会得到一个错误 数据集: Date <- as.Date(c('2017-10-16', '2017-10-16', '2017-10-17', '2017-10-17', '2017-10-18', '2017-10-18',

我正在dplyr中使用summary_all函数

当我使用不推荐的版本时,“每个汇总”效果很好,但当我汇总所有内容时,我会得到一个错误

数据集:

Date <- as.Date(c('2017-10-16',
              '2017-10-16',
              '2017-10-17',
              '2017-10-17',
              '2017-10-18',
              '2017-10-18',
              '2017-10-19',
              '2017-10-19',
              '2017-10-20',
              '2017-10-20'))

Source <- as.Date(c('2017-11-29',
                '2017-11-30',
                '2017-11-29',
                '2017-11-30',
                '2017-11-29',
                '2017-11-30',
                '2017-11-29',
                '2017-11-30',
                '2017-11-29',
                '2017-11-30'))

Column1 <- c("A","A","A","A","A","B","B","B","B","B")

Column2 <- c("A","A","A","A","A","B","B","B","B","B")


Revenue <- c(206.88,
         210.88,
         194.13,
         200.13,
         170.00,
         170.00,
         746.65,
         736.65,
         772.00,
         772.00)

Cost <- c(100.88,
      10.88,
      85.13,
      100.13,
      170.00,
      100.00,
      46.65,
      50.65,
      23.00,
      24.00)

df <- data.frame(Date, Source, Column1, Column2, Revenue, Cost)
这是每个摘要的代码:

by_date_test<-df %>%
group_by(Date) %>%
summarise_each(funs(sum), -c(`Column1`, 
                             `Column2`))
当我尝试使用
summary_all
时,我得到的错误是:

 by_date_test<-df %>%
  group_by(Date) %>%
  summarise_all(funs(sum), -c(`Column1`, 
                              `Column2`))

Error in -c(Column1, Column2) : invalid argument to unary operator
按日期测试%
分组单位(日期)%>%
总结所有(funs(sum),-c(`Column1`,
`第2栏`)
-c(第1列,第2列)中出错:一元运算符的参数无效
我总结这些有什么不对吗?另外,我的实际数据集大约有1000列,我想排除选定的列

谢谢

y\u日期\u测试%
y_date_test<-df %>%
  group_by(Date) %>%
  summarise_at(vars(-Column1, -Column2), sum)
分组单位(日期)%>% 汇总(变量(-第1列,-2列),总和)
演示:

分组依据(mtcars,cyl)%>%
总结(变量(-mpg,-wt),平均值)
##tibble:3 x 9
#气缸显示hp drat qsec与am齿轮carb
#                                      
# 1     4 105.1364  82.63636 4.070909 19.13727 0.9090909 0.7272727 4.090909 1.545455
# 2     6 183.3143 122.28571 3.585714 17.97714 0.5714286 0.4285714 3.857143 3.428571
# 3     8 353.1000 209.21429 3.229286 16.77214 0.0000000 0.1428571 3.285714 3.500000

请提供一个最小的可复制示例将其更改为一个可复制示例您实际上不想总结所有列,因此
总结所有列
是一个错误的选择。似乎您想总结除第1列或第2列以外的所有内容,即“变量选择”,因此请尝试在处进行总结。我有大约1000列,我想总结除所选内容以外的所有内容。会总结你还在工作吗?是的,会。。。
 by_date_test<-df %>%
  group_by(Date) %>%
  summarise_all(funs(sum), -c(`Column1`, 
                              `Column2`))

Error in -c(Column1, Column2) : invalid argument to unary operator
y_date_test<-df %>%
  group_by(Date) %>%
  summarise_at(vars(-Column1, -Column2), sum)
group_by(mtcars, cyl) %>%
    summarise_at(vars(-mpg, -wt), mean)
# # A tibble: 3 x 9
#     cyl     disp        hp     drat     qsec        vs        am     gear     carb
#   <dbl>    <dbl>     <dbl>    <dbl>    <dbl>     <dbl>     <dbl>    <dbl>    <dbl>
# 1     4 105.1364  82.63636 4.070909 19.13727 0.9090909 0.7272727 4.090909 1.545455
# 2     6 183.3143 122.28571 3.585714 17.97714 0.5714286 0.4285714 3.857143 3.428571
# 3     8 353.1000 209.21429 3.229286 16.77214 0.0000000 0.1428571 3.285714 3.500000