[R] Plotting hourly time-series data loaded from file using plot.ts

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 16 16:35:04 CEST 2009


There is no such limitation.   There is likely a data problem with
one or more records past the 280th one.

Suggest you remove the first 280 and then divide the remaining
in half and try each half and keep dividing that way until you have
located the offending record or records.

On Thu, Jul 16, 2009 at 8:51 AM, Keith<kigiokli at gmail.com> wrote:
> Thanks Gabor,
>
> I tried a little bit, and your example works. However, it seems that
> the read.zoo has a limitation of records up to around 300 !? I took
> your suggestion and modified a little bit in order to read from the
> file which contains about 9000 records:
>
> dataTs <- read.zoo("filename.csv", header=TRUE, sep=",", format =
> "%H:%M:%S %m.%d.%Y", tz = "", strip.white = TRUE)
>
> and the R always shows up the message:
>
> Error in read.zoo("filename.csv", header = TRUE, sep = ",", format =
> "%H:%M:%S %m.%d.%Y",  :
>  index contains NAs
>
> At the beginning, I thought it is the problem of NA, and tried to
> removed the records with NA. Still, the message appeared until I
> reduce the number of records to around 280 and it works well with or
> without NAs.
>
> Does anyone has any idea to solve the problem?
>
> Regards,
> Keith
>
> On Wed, Jul 15, 2009 at 5:08 PM, Gabor
> Grothendieck<ggrothendieck at gmail.com> wrote:
>> Try the zoo package:
>>
>> Lines <- "time[sec] , Factor1 , Factor2
>> 00:00:00 01.01.2007 , 0.0000 , 0.176083
>> 01:00:00 01.01.2007 , 0.0000 , 0.176417
>> 11:00:00 10.06.2007 , 0.0000 , 0.148250
>> 12:00:00 10.06.2007 , NA , 0.147000
>> 13:00:00 10.06.2007 , NA , 0.144417"
>>
>> library(zoo)
>> library(chron)
>> z <- read.zoo(textConnection(Lines), sep = ",", header = TRUE,
>>        format = "%H:%M:%S %m.%d.%Y", tz = "", strip.white = TRUE)
>> plot(z)
>>
>> and read the three vignetttes (pdf documents) that come with it.
>>
>>
>> On Wed, Jul 15, 2009 at 10:07 AM, Keith<kigiokli at gmail.com> wrote:
>>> Hello everyone,
>>>
>>> I am just a tyro in R and would like your kindly help for some
>>> problems which I've been struggling for a while but still in vain.
>>>
>>> I have a time-series file (with some missing value ) which looks like
>>>
>>> time[sec] , Factor1 , Factor2
>>> 00:00:00 01.01.2007 , 0.0000 , 0.176083
>>> 01:00:00 01.01.2007 , 0.0000 , 0.176417
>>> [ ... ]
>>> 11:00:00 10.06.2007 , 0.0000 , 0.148250
>>> 12:00:00 10.06.2007 , NA , 0.147000
>>> 13:00:00 10.06.2007 , NA , 0.144417
>>> [ ... ]
>>>
>>> and I would like to do some basic time-series analyses using R. The
>>> first idea is to plot these time-series events and the main problem
>>> was the handling of the date/time format in the 1st column. I was
>>> using the script below to deal with:
>>>
>>> data <- read.table("file",header=TRUE,sep=",",colClasses=c("character","numeric","numeric"))
>>> data$time.sec. <- as.POSIXct(data$time.sec.,format="%H:%M:%S %d.%m.%Y")
>>> dataTs <- as.ts(data)
>>> plot.ts(dataTs)
>>>
>>> Then, the plot showed up with 3 subplots in one plot. The 1st is the
>>> linear line with the x-axis being just the sequence of orders and
>>> y-axis being wrong numbers which is completely wrong. The 2nd and the
>>> 3rd are correct but the x-axis is still wrong. Does anyone know how to
>>> plot correct Factor1 and Factor2 with respect to the 1st column time
>>> format? Or, probably should I use some other packages? Besides, how
>>> can I plot these two time-series data (Factor1 and Factor2) in two
>>> separate plots?
>>>
>>> Best regards,
>>> Keith
>>>
>>> ______________________________________________
>>> R-help at r-project.org 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.
>>>
>>
>




More information about the R-help mailing list