Hi Guys, I'm cooking up my time series code. I want a data frame with first column as timestamp in POSIXlt format. I hit on this the problem of how to create an array/list/vector of POSIXlt objects. Code is as follows> dtt=array(dim = 2) > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT")) > dtt[1] NA NA> t[1] "0007-07-12 13:20:01 GMT"> dtt[1]=tWarning message: In dtt[1] = t : number of items to replace is not a multiple of replacement length> class(dtt)[1] "list"> class(t)[1] "POSIXt" "POSIXlt"> unclass(t)$sec [1] 1 $min [1] 20 $hour [1] 13 $mday [1] 12 $mon [1] 6 $year [1] -1893 $wday [1] 4 $yday [1] 192 $isdst [1] 0 attr(,"tzone") [1] "GMT" Seems like POSIXlt is matrix in this case. Any suggestions? Cheers, B _________________________________________________________________ [[elided Hotmail spam]] [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Feb-17 20:53 UTC
[R] How to make a vector/list/array of POSIXlt object?
Normally one uses POSIXct rather than POSIXlt for storage. See R News 4/1 for more info on date and time classes. On Feb 17, 2008 3:45 PM, Bo Zhou <bozhou1981 at hotmail.com> wrote:> > Hi Guys, > > I'm cooking up my time series code. I want a data frame with first column as timestamp in POSIXlt format. > > I hit on this the problem of how to create an array/list/vector of POSIXlt objects. Code is as follows > > > > > dtt=array(dim = 2) > > t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT")) > > dtt > [1] NA NA > > t > [1] "0007-07-12 13:20:01 GMT" > > dtt[1]=t > Warning message: > In dtt[1] = t : > number of items to replace is not a multiple of replacement length > > class(dtt) > [1] "list" > > class(t) > [1] "POSIXt" "POSIXlt" > > unclass(t) > $sec > [1] 1 > > $min > [1] 20 > > $hour > [1] 13 > > $mday > [1] 12 > > $mon > [1] 6 > > $year > [1] -1893 > > $wday > [1] 4 > > $yday > [1] 192 > > $isdst > [1] 0 > > attr(,"tzone") > [1] "GMT" > > > > Seems like POSIXlt is matrix in this case. > > Any suggestions? > > Cheers, > > B > _________________________________________________________________ > [[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Seemingly Similar Threads
- The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
- POSIXlt, POSIXct, strptime, GMT and 1969-12-31 23:59:59
- The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
- timezone tests and R-devel
- timezone tests and R-devel