Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of operations in summarise [closed]

Tags:

What is happening in the first line of code and why does the result differ from the two next results?

library(tidyverse) library(magrittr)  data.frame(A=c(2,2),B=c(1,1)) %>%    summarise(A = sum(A),B = sum(B), D=sum(A)-sum(B)) 

yields D=0

data.frame(A=c(2,2),B=c(1,1)) %>%    summarise(A = sum(A),B = sum(B), D=sum(A-B) ) 

yields in D=2

data.frame(A=c(2,2),B=c(1,1)) %>%    summarise(sum_A = sum(A),sum_B = sum(B), D=sum(A)-sum(B)) 

yields in D=2.

I can't seem to come up with an explanation to how the D=0 can be a result of such an operation. How can D=0 be a sensible result?

like image 474
Martin Avatar asked Nov 30 '17 10:11

Martin


1 Answers

It is a bug, see https://github.com/tidyverse/dplyr/issues/3233. It is fixed in 0.7.4.9001.

like image 132
trinalbadger587 Avatar answered Oct 21 '22 05:10

trinalbadger587