Skip to content

Dates as POSIXt

2 messages · Daniel Haugstvedt, Brian Ripley

#
When I try to do linear interpolation between financial contracts with maturities on different dates in different months I have come across some behavior I haven't seen before. 

I have a data frame in R which is loaded from an access database so I can't provide a working example. It was loaded using this code:
When I look at the Date column I get this result
POSIXt[1:25311], format: "2003-09-03 06:00:00" "2003-09-03 06:00:00" ...

I have newer seen data as POSIXt, only as POSIXct or POSIXlt. It is the behavior of this class is that I would like more information about. Online searching have only told me that it is a virtual class. 

When I do some calculations to get the dates of maturity into the data frame I find this behavior. (For simplicity assume that the only month is March.)
which works fine and gives me the dates I want but it is not readable with human eyes. When I try
it breaks my DF
List of 2015
$ : num [1:2015] 0 0 0 0 0 0 0 0 0 0 ...
$ : int [1:2015] 0 0 0 0 0 0 0 0 0 0 ...
$ : int [1:2015] 0 0 0 0 0 0 0 0 0 0 ...
$ : int [1:2015] 16 16 16 16 16 16 16 16 16 16 ...
$ : int [1:2015] 0 0 0 0 0 0 0 0 0 0 ...
$ : int [1:2015] 104 104 104 104 104 104 104 104 104 104 ...
$ : int [1:2015] 5 5 5 5 5 5 5 5 5 5 ...
$ : int [1:2015] 15 15 15 15 15 15 15 15 15 15 
 .
 .
 .
[list output truncated]

Now I wonder why I can't use POSIXlt in my data frame (I know I shouldn't but that is not the question) and if I can use POSIXt like the original data?  It is human readable but also suited for calculation (e.g. DF$Date >  as.POSIXct("2005-12-01") works nicely.


Best regards
Daniel Haugstvedt
Ph.D. student
NTNU, Trondheim, Norway
#
You cannot have a POSIXlt column in a data frame: if you did your 
homework you would know it is because it is length-9 list.

I don't know why str() is reporting POSIXt as a class, and your example 
is not reproducible.  Normally date-times have class

 > class(Sys.time())
[1] "POSIXct" "POSIXt"

and I suspect you actually have a POSIXct column.  But the order of 
these two classes is not important and has changed over the years.
On 05/11/2012 07:51, Daniel Haugstvedt wrote: