[R] simple read in with zoo using POSIXlt

knavero knavero at gmail.com
Sat Apr 14 22:29:57 CEST 2012


Achim Zeileis-4 wrote
> 
> You just need to declare that the index is in two columns (1 and 2) and 
> then provide a function that extracts a suitable object from it:
> 
> read.zoo("test.txt", header = FALSE, index = 1:2,
>    FUN = function(x, y) strptime(paste(x, y), "%d/%m/%Y %H:%M"))
> 
> Use an additional as.POSIXct(...) around the strptime() call if you want
> to use POSIXct instead of POSIXlt which is typically recommended. 
> 

Ah I see. Yeah I'm familiar with the index = 1:2 argument of read.zoo.
However, I'm not sure if it's necessary here since I'm specifying one of the
arguments to be sep = "\t", and thus it sees one timestamp column as
"%m/%d/%Y %H:%M" format and the second column, being the data column,
separated via tab. So I'll try using strptime() and POSIXlt() on that column
as FUN = function(idx) as.POSIXlt(strptime(idx, format = "%m/%d/%Y %H:%M",
tz = "PDT")).

The reason I plan on using POSIXlt here as opposed to POSIXct is for
functionality reasons such that the class itself contains a list of vectors
that can be accessed i.e. sec, min, hour, ...wday, yday, etc. I'll post the
results in a few mins after testing it out on the shell here. Thanks for the
suggestion!!!  

--
View this message in context: http://r.789695.n4.nabble.com/simple-read-in-with-zoo-using-POSIXlt-tp4557138p4557990.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list