[R] simple read in with zoo using POSIXlt

Achim Zeileis Achim.Zeileis at uibk.ac.at
Sat Apr 14 15:28:43 CEST 2012

On Sat, 14 Apr 2012, knavero wrote:

> Easy question a bit. So here's my code:
> http://pastebin.com/F4iQPVy5
> I am trying to read in a series of timestamps. However with POSIXlt as 
> FUN in read.zoo, the output is merely two numbers and is not the output 
> that I'm hoping for. The code above should reproduce the error.

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.

See vignette("zoo-read", package = "zoo") for more examples.

> Here is code that shows what I want it to do:
> http://pastebin.com/GEPZ5R9B
> The problem though, is that it's not that elegant since POSIXlt is outside
> of read.zoo. Wondering if there's a way to put POSIXlt inside read.zoo and
> compress things a bit to make the code run faster. Any ideas? Thanks.
> Also, if there's any issues reading the file i uploaded to dropbox directly
> off of the net with the code above, just use this:
> http://r.789695.n4.nabble.com/file/n4557138/test.txt test.txt
> Hope I covered everything in a compact reproducible manner. Sorry if I made
> a noob mistake. Still kind of new.
> --
> View this message in context: http://r.789695.n4.nabble.com/simple-read-in-with-zoo-using-POSIXlt-tp4557138p4557138.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> 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.

More information about the R-help mailing list