[R] uneven vector length issue with read.zoo?

Gabor Grothendieck ggrothendieck at gmail.com
Thu May 3 12:36:29 CEST 2012


On Wed, May 2, 2012 at 3:55 PM, knavero <knavero at gmail.com> wrote:
> I truncated and simplified my code and the read in data that I'm working with
> to isolate the issue. Here is the read in data and R script respectively:
>
> http://r.789695.n4.nabble.com/file/n4604287/test.csv test.csv
>
> http://pastebin.com/rCdaDqPm
>
> Here is the terminal/R shell output that I hope the above replicates on your
> screen:
>> source("elecLoad.r", echo = TRUE)
>
>> #Load packages
>> library(zoo)
>
>> library(chron)
>
>> #Initial assignments for format (fmt), timezone (TZ), and user
>> #defined chron function (chr)
>> fmt = "%m/%d/%y %I:%M %p"
>
>> TZ = "PDT"
>
>> chr = function(x) as.chron(x, fmt)
>
>> #Read in data as zoo object using relevant arguments in read.zoo()
>> #for details of arguments, see Kevin Navero or see ?read.zoo
>> #and ?read.table .... [TRUNCATED]
> Error in read.zoo("http://dl.dropbox.com/u/41922443/test.csv", skip = 1,  :
>  index has bad entries at data rows: 14 15 16 17 18 19 20 21 22 23 24 25 26
> 27 28
>
> I was hoping that the "NULL" in colClasses() would've taken care of this
> uneven vector length issue, however, that was not the case. Any ideas?
> Thanks in advance. Sorry if my post didn't follow the forum rules exactly. I
> tried to make small scale reproducible code and what not. I'm still a bit of
> a noob here and there.
>

Try this using the same library statements, fmt and chr from ijn post:

URL <- ""http://dl.dropbox.com/u/41922443/test.csv"
DF1 <- read.table(URL, skip = 1, header = TRUE, sep = ",", fill = TRUE,
  as.is = TRUE)
DF2 <- na.omit(DF1[1:2])
z <- read.zoo(DF2, FUN = chr)



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list