I think this is because the numeric Inf
you got, is converted back to Date Class and it results to NA. (of class Date).
If you want to keep Inf
you need to store your date as numeric, or as character (not as Date) using a custom function to change NA
of class Date to "Inf"
as character (not Inf
numeric). I am not sure Inf
of class
Date as any meaning.
I think all this is the way R deals with date between numeric, character and class Date.
Some code to complement
# Your date from 01-01 to 10-01
y <- seq(from = as.Date('2018-01-01'), to = as.Date('2018-01-10'), 1)
# When trying to select everything above 11-01.
# there is none so it is all false
all(y > as.Date('2018-01-11'))
#> [1] FALSE
# and it subsets to nothing because all indexes are FALSE
y[y > as.Date('2018-01-11')]
#> Date of length 0
# min of an object of length 0 is set to Inf.
min(numeric(0))
#> Warning in min(numeric(0)): aucun argument trouvé pour min ; Inf est
#> renvoyé
#> [1] Inf
# and it is NA for date, because the numeric Inf is converted back to Date class
as.Date(Inf, origin = "1970-01-01")
#> [1] NA
# it is NA as it doesn't exist. That why you got the result.
min_y <- min(y[y > as.Date('2018-01-11')])
#> Warning in min.default(structure(numeric(0), class = "Date"), na.rm =
#> FALSE): aucun argument trouvé pour min ; Inf est renvoyé
class(min_y)
#> [1] "Date"
min_y
#> [1] NA
cat(min_y)
#> Inf
# same as as.numeric
as.numeric(min_y)
#> [1] Inf
as.character(min_y)
#> [1] NA
# print use format
format(min_y)
#> [1] NA
# So cat seems to convert to numeric
Created on 2019-01-03 by the reprex package (v0.2.1)