Skip to content

still need read.zoo command help

4 messages · Henry, Hasan Diwan, Gabor Grothendieck

#
The problem now is it looks like my read.zoo isn't working.
Sorry for sort of double posting.
Someone please assist if you have time with my read.zoo command line.
my data is as just below this line, a time stamp and a real number with a
comma sep.

10/11/2011 23:00:06,432.12


z=read.zoo("Kevin-0-comma-ITPower.txt",
                       format="%m/%d/%Y %H:%M:%S",
			tz="",
			FUN=NULL,
			regular=FALSE,
			header=FALSE,
			sep=",",
			index.column=1)

library(zoo)
library(chron)
#this code from Gabor Grothendieck - thanks
# 15 minute aggregate averages
m15 <- times("00:15:00")
ag15 <- aggregate(z, trunc(time(z), m15), mean)

write.zoo(ag15,file="ITPower15minv2.txt",index.name="Time",row.names=FALSE,col.names=FALSE)
# this may also have a problem.

#2011-10-11 2011-10-11 is all that is written in the file

#data in the "Kevin-0-comma-ITPower.txt starts like this..
10/11/2011 23:00:06,432.12
10/11/2011 23:02:09,432.42
10/11/2011 23:05:00,432.42
10/11/2011 23:07:10,432.12
10/11/2011 23:10:01,432.12
10/11/2011 23:12:12,432.22
10/11/2011 23:15:00,432.22
10/11/2011 23:20:00,432.22
10/11/2011 23:22:14,432.32
10/11/2011 23:25:01,432.32
10/11/2011 23:26:15,432.22
10/11/2011 23:30:01,432.22
10/11/2011 23:31:17,432.32
10/11/2011 23:35:00,432.32
10/11/2011 23:36:18,432.22
10/11/2011 23:37:18,432.72
10/11/2011 23:39:19,432.23



--
View this message in context: http://r.789695.n4.nabble.com/still-need-read-zoo-command-help-tp4398897p4398897.html
Sent from the R help mailing list archive at Nabble.com.
#
Henry,
You're reading a CSV with read.zoo. This is not likely to work. The
way I'd do this is:
data <- read.csv('/tmp/Kevin-0-comma-ITPower.txt', header=FALSE)
z <- zoo(data[,2], order.by=as.POSIXct(data[,1], format='%d/%m/%y
%H:%M:%S') # or whatever your format actually is...

-- H
Sent from my mobile device
Envoyait de mon portable
#
On Fri, Feb 17, 2012 at 7:54 PM, Henry <hccoles at lbl.gov> wrote:
The read.zoo statement should come AFTER the library statements, not
before, and the read.zoo should be specified like this where fmt was
also defined in my response to your prior post:

Lines <- "10/11/2011 23:00:06,432.12
10/11/2011 23:02:09,432.42
10/11/2011 23:05:00,432.42"

library(zoo)
library(chron)
fmt <- "%m/%d/%Y %H:%M:%S"
z <- read.zoo(text = Lines, FUN = as.chron, format = fmt, sep = ",")

Also regarding the comment by the other poster, read.zoo reads csv data fine.

Be sure you have read and assimilated ?read.zoo and also
vignette("zoo-read") which is a document entirely devoted to read.zoo
examples.
#
On Fri, Feb 17, 2012 at 8:16 PM, Hasan Diwan <hasan.diwan at gmail.com> wrote:
If you wanted to read in the csv data with a first column in the
format shown by the poster, no header and a POSIXct index then it
would be done like this where Lines and fmt are defined in my last
post:

 read.zoo(text = Lines, format = fmt, tz = "", sep = ",")

however, note that the poster intends subsequent use of chron, not
POSIXct.  Also see R News 4/1 regarding choosing index classes.