[Rd] Date class shows Inf as NA; this confuses the use of is.na()

MacQueen, Don m@cqueen1 @ending from llnl@gov
Fri Jun 8 23:12:17 CEST 2018


> as_date
Error: object 'as_date' not found

Must be from some not-named package...

But don't confuse the format of an object when printed with its underlying value:

> as.Date(Inf,origin = '1970-01-01')
[1] NA

> str(as.Date(Inf,origin = '1970-01-01'))
 Date[1:1], format: NA

> as.numeric(as.Date(Inf,origin = '1970-01-01'))
[1] Inf

> is.na(Inf)
[1] FALSE

> is.na(as.Date(Inf,origin = '1970-01-01'))
[1] FALSE

> str(as.Date(27,origin = '1970-01-01'))
 Date[1:1], format: "1970-01-28"

> as.numeric(as.Date(27,origin = '1970-01-01'))
[1] 27

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 6/8/18, 1:02 PM, "R-devel on behalf of Werner Grundlingh" <r-devel-bounces using r-project.org on behalf of wgrundlingh using gmail.com> wrote:

    In the following example, the date class shows Inf as NA
    
    > as_date(Inf, origin = '1970-01-01')
    [1] NA
    
    This is misleading as is.na() reports incorrectly
    
    > is.na(as_date(Inf, origin = '1970-01-01'))
    [1] FALSE
    
    The correct approach here would probably to have an Inf (and -Inf)
    *displayed* rather than NA.
    
    	[[alternative HTML version deleted]]
    
    ______________________________________________
    R-devel using r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-devel
    



More information about the R-devel mailing list