user2405589
user2405589

Reputation: 968

need finite 'xlim' values on Zoo object plotting

I have the following zoo object :

x<-read.zoo("values.txt",format="%H:%M:%OS",sep=",",header=F,FUN=as.POSIXct)

x is like the below:

2015-01-20 17:39:56 367 0
2015-01-20 17:39:56 236 0
2015-01-20 17:39:58 542 0
2015-01-20 17:39:58 260 0

Now I aggregate over the second time interval to get values per second instead of the millisecond level: > x_uniq<-aggregate(x,format(time(x),"%H:%M:%S"),mean)

x_uniq is like the below :

17:39:55 403.0000 0.0
17:39:56 301.5000 0.0
17:39:58 401.0000 0.0
17:40:00 607.0000 0.0

Whe I try to plot it however I get the below error:

plot(x_uniq,plot.type = "single", col = c("red", "blue"),lwd = 2)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

Now it is, the way I understand it, because the times have now been converted to characters. But I am not sure how to convert this back. Could anyone please help? Thanks!

Upvotes: 0

Views: 303

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269311

The question omitted the input and only showed the output of the read.zoo statement so we don't really know what you have but assuming it looks like the following try this:

Lines <- 
"2015-01-20 17:39:56,367,0
2015-01-20 17:39:56,236,0
2015-01-20 17:39:58,542,0
2015-01-20 17:39:58,260,0"

library(zoo)
z <- read.zoo(text = Lines, sep = ",", tz = "", aggregate = mean)
plot(z)

Upvotes: 0

Related Questions