[R-sig-finance] Trouble with zoo + POSIXct/POSIXlt

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 18 13:39:27 CEST 2006


Don't know what z is but if its supposed to be x then, yes,
you have created an invalid zoo object since the index entries
must be unique.  The second try does not make sense since
x[,1]= is not a valid argument to read.zoo and the third one
is erroneous as it specifies an expression whereas it should
specify a function.

I think you want:

read.zoo(myfile, sep = ',' , FUN = function(x) as.POSIXct(strptime(x,
my.format)))

or read it in using the its package and then use xx <- as.zoo(x) where x is
the its object.

On 4/18/06, icosa atropa <icos.atropa at gmail.com> wrote:
> After successfully using the 'its' package, I've been trying out 'zoo'
> for some of its more advanced functions.  I can coerce my its objects
> into zoo objects without problem.
> Yet I'm having trouble understanding the read.zoo function's errors.
> It seems that my index class, POSIXct, is the problem.
>
> I have csv files like this:
> 7/23/2003 4:05:51 PM,9.35,98.027
> 7/23/2003 4:20:51 PM,9.32,97.954
>
> -----------------------
> #First try:
> >my.format = "%m/%d/%Y %I:%M:%S %p"
> >x=read.zoo(myfile, sep=',', skip=30, format=my.format)
> > z
>             V2      V3
> 2003-07-23 9.35  98.027
> 2003-07-23 9.32  97.954
> > summary(z)
> Error in "row.names<-.data.frame"(`*tmp*`, value = NULL) :
>        invalid 'row.names' length
> #format= doesn't seem to work here, error means index not #unique?
> #
> #Second try,
> #This works:
> >x=read.table(myfile, sep=',' , skip=30,\
> x[,1]=as.POSIXct(strptime(x[,1], format=my.format,\ tz='UTC+6'))
> > y=zoo(x[,2:3], order.by=x[,1])
> #
> #but this doesn't:
> #
> >x=read.zoo(my.file, sep=',',skip=30,\
> FUN=as.POSIXct(strptime(as.character(x), format=my.format,
> tz='UTC+6')) )
> Error in read.zoo(files[1], sep = ",", skip = 30, FUN =
> as.POSIXct(strptime(as.character(x),  :
>        couldn't find function "FUN"
> ---------
> Any idea what the last error message means?
> TIA,
> christian
>
> _______________________________________________
> R-sig-finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>



More information about the R-sig-finance mailing list