In R, if you subtract a number from NA, it will return NA:
> x <- 1
> NA - x
[1] NA
But if you try to subtract the date from NA, it will return an error:
> x <- as.Date("2014-04-22")
> NA - x
Error in `-.Date`(NA, x) : can only subtract from "Date" objects
I am wondering why R returns an error. As I understand it, Date objects are just an expression of the integer difference from the origin (by default - 1970-01-01).
source
share