[R] POSIX

Gabor Grothendieck ggrothendieck at myway.com
Thu Dec 9 23:04:15 CET 2004


Omar Lakkis <abu3ammar <at> gmail.com> writes:

: 
: if I have a variable of type "POSIXt"  "POSIXct" like "1969-12-31
: 19:00:01 EST" how can I dynamicly get the year (or years if vector)
: and month?

Enter unclass(as.POSIXlt(x)) to see the components available to you
when using POSIXlt.  These include the year component which is the year
minus 1900 and the mon component which is the month number
noting that January is 0, February is 1, etc.  Also note that
the year and month can differ in different time zones so you may need
tz = "GMT" if you need it with respect to GMT time, say.

You can also use something like format(x, "%y-%m").  tz= comment
applies here too.  ?strptime lists the various % codes.

You may be better off using Date class if your granularity is year
and month or if you have regularly spaced monthly data you can use a ts 
series with frequency of 12.

The article in RNews 4/1 gives many more examples and pointers to
additional information.




More information about the R-help mailing list