[R] simple read in with zoo using POSIXlt

knavero knavero at gmail.com
Sat Apr 14 23:06:28 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.
> 
> See vignette("zoo-read", package = "zoo") for more examples.
> Z
> 

Unfortunately, it's not working as I hoped for. Let me elaborate,

new code:

http://pastebin.com/axpPB6M8

So for this, I understand that the read in works very well with POSIXct, but
I want to utilize the vectors contained with the POSIXlt class (wday, yday,
mon, etc.). Here's how the POSIXct read.zoo looks like in the shell when
copy pasted:

> test = read.zoo("http://dl.dropbox.com/u/41922443/test.txt", 
+    header = FALSE, sep = "\t",
+    FUN = function(idx) as.POSIXct(strptime(idx, 
+       format = fmt, tz = "PDT"), format = fmt, tz = "PDT"),
+    colClasses = rep(c(NA, "numeric", "NULL"), c(1, 1, 0)),
+    aggregate = tail1)
> test
2010-01-07 00:15:00 2010-01-07 00:30:00 2010-01-07 00:45:00 2010-01-07
01:00:00 
           1333.620            1333.388            1335.343           
1334.251 
2010-01-07 01:15:00 2010-01-07 01:30:00 2010-01-07 01:45:00 2010-01-07
02:00:00 
           1331.589            1328.695            1329.151           
1329.077 
2010-01-07 02:15:00 2010-01-07 02:30:00 
           1327.649            1326.789 

This is good when you just eyeball it, HOWEVER, when the date/time is looked
at by the machine, it doesn't see vectors that can be accessed, but the lame
numerical/double that is the UTC time from 1960 or whatever in seconds.
Proof of this is the following:

> unclass(index(test))
 [1] 1262823300 1262824200 1262825100 1262826000 1262826900 1262827800
 [7] 1262828700 1262829600 1262830500 1262831400
attr(,"tzone")
[1] "PDT"

Now with this code:

http://pastebin.com/pr2X78sX

This just pisses me off....let me elaborate...or well, eff it. I'll just
copy paste and you'll get my point:

> test = read.zoo("http://dl.dropbox.com/u/41922443/test.txt", 
+    header = FALSE, sep = "\t",
+    FUN = function(idx) as.POSIXlt(strptime(idx, 
+       format = fmt, tz = "PDT"), format = fmt, tz = "PDT"),
+    colClasses = rep(c(NA, "numeric", "NULL"), c(1, 1, 0)),
+    aggregate = tail1)
> test
       0 
1326.789 

Basically, what the hell is 0 and 1326.789 doing there?.....right? 


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



More information about the R-help mailing list