Skip to content
Prev 314444 / 398503 Next

Question on creating Date variable

On Jan 1, 2013, at 9:02 AM, jim holtman wrote:

            
Useful procedure to prevent loss of trailing ".00"'s, ... but just to  
clarify, sprintf never returns a numeric class object, but rather  
returns a character representation of one. (Which is an appropriate  
class for `as.POSIXct`.)
Just as those values are printed character representations of what is  
internally a numeric vector even though it will not admit to being  
such until coerced:

 > Sys.Date()
[1] "2013-01-01"
 > is.numeric(Sys.Date())
[1] FALSE
 > as.numeric(Sys.Date())
[1] 15706
 > as.numeric(as.POSIXct(Sys.Date()))
[1] 1356998400
 >