R subtracting 1 month from today's date gives NA

前端 未结 2 1490
北恋
北恋 2020-12-11 16:36

I have a script in which I subset my data according to some set time periods and wanted to subset all the records that had occurred in the last month.

However if I t

2条回答
  •  臣服心动
    2020-12-11 17:21

    One month ago is non-defined in this context. February 29th only exists in leap years.

    See the lubridate documentation:

    Note: Arithmetic with periods can results in undefined behavior when non-existent dates are involved (such as February 29th in non-leap years). Please see Period-class for more details and %m+% and add_with_rollback for alternative operations.

    The lubridate package can handle what you are doing, but you need to perform the operaton using %m+%.

提交回复
热议问题