[R] Posix Problem, difftime
Don MacQueen
macq at llnl.gov
Thu Oct 17 22:44:45 CEST 2002
Your first step would be to use POSIXct, not POSIXlt.
POSIXlt objects are actually lists, and cbind() doesn't have meaning for lists.
POSIXct objects are actually numeric vectors, so they can be combined
into matrices.
However, matrices are either numeric or character, so POSIXct objects
combined into a matrix will get displayed in their numeric form:
> cbind(ISOdatetime(2002,1:2,3,13,0, 0),ISOdatetime(2001,1:2,3,13,0,0))
[,1] [,2]
[1,] 1010091600 978555600
[2,] 1012770000 981234000
Checking for missing hours is pretty easy with POSIXct objects:
> foo <- ISOdatetime(1901,1,2,c(11:14,16:18),0,0)
> foo
[1] "1901-01-02 11:00:00 PST" "1901-01-02 12:00:00 PST" "1901-01-02
13:00:00 PST" "1901-01-02 14:00:00 PST" "1901-01-02 16:00:00 PST"
[6] "1901-01-02 17:00:00 PST" "1901-01-02 18:00:00 PST"
> diff(as.numeric(foo))
[1] 3600 3600 3600 7200 3600 3600
> any(diff(as.numeric(foo)) != 3600)
[1] TRUE
Because an hour = 3600 seconds.
Regarding the 2 hour interval, have you considered that there may be
a transition from daylight savings time to standard time? I don't
know if that was in effect in 1901 in whatever timezone you're in,
and if it was, whether 29 Oct was the day of transition, but it's
worth considering. Other than that, in order to help, I'd have to see
what your data looked like before it was in R, and what code you used
to convert it to POSIXt.
-Don
At 11:51 AM -0500 10/17/02, Matthew Pocernich wrote:
>I am having a series of problems using date time data that has been
>converted into a POSIXt and POSIXlt classes. I have hourly time
>series data from 1900 that has been converted from text data.
>
>I assume most of my problems come from a mis-underdanding of the
>POSIX class. My matrix named (aa) for this year is approx 8700 by
>4. When I try to calculate the length of posit column ( which is
>the date and time) I get
>
>> length(aa$posit)
>[1] 9
>
Because it's a list with 9 elements. Try unclass(aa$posit) to see.
>When I try to combined POSIX columns or manipulate them like
>matrices, I have problems such as
>
>> cbind(aa$posit, aa$posit)
>Error in cbind(...) : cannot create a matrix from these types
>
>Ultimately I would like to check to make certain the hourly data is
>not missing. I tried doing this using vectors such as
>difftime(aa$posit, lag(aa$posit)). This didn't work. Ultimately I
>used a for loop, which is very slow and it produces the following
>error. The last column is the difference in times between
>subsequent posit values. The fourth row shows a 2 hour gap between
>events. (This did not happen in any of the other days. )
>
>
> tide posit diffh y365 diftime
>7223 -1.25 1901-10-28 22:00:00 -2.7 301 1
>7224 -2.75 1901-10-28 23:00:00 -1.5 301 1
>7225 -2.25 1901-10-29 00:00:00 0.5 302 1
>7226 -0.25 1901-10-29 01:00:00 2.0 302 2
>7227 2.65 1901-10-29 02:00:00 2.9 302 1
>
>Any help or suggestions are greatly appreciated.
>
>Thanks,
>
>Matt
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
--------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list