On Tue, 24 Apr 2007, Tomas Mikoviny wrote: > Hi everybody, > > I work with data with following pattern > > > comm > > "Date" "Value" > 1 4/10/2007 361.2 > 2 4/11/2007 370.1 > 3 4/12/2007 357.2 > 4 4/13/2007 362.3 > 5 4/16/2007 363.5 > 6 4/17/2007 368.7 > 7 4/18/2007 354.7 > 8 4/19/2007 368.8 > 9 4/20/2007 367.1 > 10 ... ... > > and trying to convert it to time series using: > > > t=strptime(comm[1,1],"%m/%d/%Y") > > x=ts(comm, start=as.POSIXct(t)) > > Error in Math.difftime((end - start) * frequency + 1.01) : > floornot defined for "difftime" objects > > Definitely I do something wrong but I can't find what is it!
At least things: - ts() can only work with numeric time stamps (not POSIXct) - you try to create a regular series (although your data is not: there is not an observation on each day) I would recommend to create a "zoo" series with "Date" index: R> library("zoo") R> z <- zoo(comm[,2], as.Date(strptime(comm[,1], "%m/%d/%Y"))) R> z 2007-04-10 2007-04-11 2007-04-12 2007-04-13 2007-04-16 2007-04-17 361.2 370.1 357.2 362.3 363.5 368.7 2007-04-18 2007-04-19 2007-04-20 354.7 368.8 367.1 hth, Z > Can anyone help me with this? > > Thanks. > > Tomas > > ______________________________________________ > R-help@stat.math.ethz.ch 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. > > ______________________________________________ R-help@stat.math.ethz.ch 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.