大家好我有这个问题,我想计算日期之间的天数,前提是:状态A为基准日期,所有计算都必须以该日期为参考(按ID分组)我必须将状态B,C,D的日期定为较早我必须计算天数并在不同的列中显示前任。用R生成表ColID = c(1, 1, 1, 1, 1, 2, 2, 2) ColStatus = c("A", "B", "B", "C", "D", "A", "C", "C")ColDate = c("01/01/2018","02/03/2018", "05/04/2018", "04/05/2018", "04/05/2018", "02/01/2018", "04/03/2018", "05/04/2018")data.frame(ColID, ColStatus, ColDate)我如何进行计算For ColID = 1Status A = 01/01/2018Status B (I Have to select the older one) = 02/03/2018Status C = 04/05/2018Status D = 04/05/2018ResultColB = 02/03/2018 - 01/01/2018 = 60ResultColC = 04/05/2018 - 01/01/2018 = 123ResultColD = 04/05/2018 - 01/01/2018 = 123结果表(天)用R生成表ColID = c(1,2)ResultColStatusB = c(60,0)ResultColStatusC = c(123,61)data.frame(ColID, ResultColStatusB, ResultColStatusC, ResultColStatusB)该问题可以用R,Python或SQL解决,请问有什么推荐给我解决该问题的呢?
添加回答
举报
0/150
提交
取消