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

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jul 17 17:27:40 CEST 2009


Need reproducible code and data to respond.

As per the last line to every message in r-help, reduce the file to the
smallest subset that exhibits the error and post it with self contained
code that will read it in and reproduce the error message.

On Fri, Jul 17, 2009 at 10:29 AM, Keith<kigiokli at gmail.com> wrote:
> Yep, it's my mistake while manipulating the data. Now it works fine
> except there is a warning message coming out:
>
> Warning message:
> In zoo(rval, ix) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
>
> I checked the faq and some other documents, it seems this warning
> implies that I have duplicated data. However, I checked the data and
> it's hourly recorded throughout the year 2007, no duplication found.
>
> Besides, while I plot the dataset, it looked what as I expected but
> also showed the warning messages:
>
> 1: In zoo(rval, x.index[i]) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
> 2: In zoo(rval, x.index[i]) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
> 3: In zoo(rval, x.index[i]) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
> 4: In zoo(rval, x.index[i]) :
>  some methods for “zoo” objects do not work if the index entries in
> ‘order.by’ are not unique
>
> These looks the same problem again. Does anyone has any idea solving this?
>
> Regards,
> Keith
>
> On Thu, Jul 16, 2009 at 4:51 PM, Gabor
> Grothendieck<ggrothendieck at gmail.com> wrote:
>> By the way, note that read.zoo passes the ... arguments to read.table
>> and so can use the same skip= and nrows= arguments that read.table
>> uses.  These can be used to read in a subset of the rows.
>>
>> On Thu, Jul 16, 2009 at 10:35 AM, Gabor
>> Grothendieck<ggrothendieck at gmail.com> wrote:
>>> 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