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?
It is a bug, see https://github.com/tidyverse/dplyr/issues/3233. It is fixed in 0.7.4.9001.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With