我想用其他两列来求和多列,但是根据我的简单示例,summarise_if函数似乎不正确地求和。如果原始数据的“衬衫”和“裤子”列中的数字为0,为什么会对其求和?
Email <- c("A", "A")
hats <- c(1, 1)
shirts <- c(0, 0)
pants <- c(0, 0)
Sales.ID <- c(1, 1)
Billing.Date <- c(1, 1)
test <- cbind(Email, hats, shirts, pants, Sales.ID, Billing.Date)
test <- as.data.frame(test)
test%>% group_by(Billing.Date, Sales.ID) %>% summarize_if(is.numeric,sum,na.rm = TRUE)
预期输出:
Billing.Date Sales.ID hats shirts pants
1 1 2 0 0
实际输出:
Billing.Date Sales.ID hats shirts pants
1 1 2 2 2