如何从结束日期和天数计算开始日期

时间:2019-08-10 18:48:46

标签: r date days

我有一列带有结束日期,另一列带有天数。我想根据此信息计算开始日期。

结束日期:2019年7月15日; 6/10/2019
天数:10; 9 我想根据R中的上述信息计算开始日期。

2 个答案:

答案 0 :(得分:2)

lubridate包提供了将字符串转换为Date(在这种情况下为mdy)的函数。然后,您只需从结束日期中减去天数即可。

ed = c("7/15/2019", "6/10/2019")
n = c(10, 9)
lubridate::mdy(ed) - n
#[1] "2019-07-05" "2019-06-01"

答案 1 :(得分:1)

考虑使用基数R进行直接减法:

// in one file
global.log = someCoolLogger();
// in another file
log.info('hello world');
// or if its a variable
global.log = 'INFO'