【发布时间】:2020-12-09 11:11:07
【问题描述】:
我想总结 Col1 中 Col2 等于 0 的行。并将总和添加到零之后的第一个值。我在下面展示一个例子。我在数据框中有不同的产品。
Date <- seq(as.Date("2021-01-01"), as.Date("2021-01-07"), by = "day")
Product<-rep("A",7)
Col1 <- c(2, 5, 1, 3, 2, 1, 2)
Col2 <- c(40, 0, 0, 0, 0, 0, 50)
Expected <- c(40, 0, 0, 0, 0, 0, 62)
TD <- data.frame(Date, Product, Col1, Col2, Expected)
【问题讨论】: