[R] Posix Problem, difftime
Thomas Lumley
tlumley at u.washington.edu
Thu Oct 17 23:27:36 CEST 2002
On Thu, 17 Oct 2002, Matthew Pocernich wrote:
> 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
As it says, you can't create matrix from these types. Matrices can only
hold numbers or characters. You can create a dataframe.
> 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
No, lag() just adjusts the time series attributes of a vector.
You could do
n<-length(a$posit)
difftime(a$posit[1:(n-1)],a$posit[2:n])
> 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.
At least in my time zone this is correct. There was a 2 hour interval
between 1901-10-29 00:00:00 and 1901-10-29 01:00:00. Note that 1901-10-28
is the last Saturday in October: it was the end of summer time.
> as.POSIXlt(ISOdate(1901,10,29))$isdst
[1] 0
> as.POSIXlt(ISOdate(1901,10,28))$isdst
[1] 1
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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