[R-SIG-Finance] [Fwd: Re: stuck on data]

zubin binabina at bellsouth.net
Thu Dec 25 19:21:55 CET 2008


Gabor, thx for the direction, got it to work by reading the fAQ 
vignette, just needed to say

dzoo <- zoo(dsmallna$total_Cases, dsmallna$z)

-zubin


Gabor Grothendieck wrote:
> Please provide ***reproducible*** examples: baseline.csv is missing
> from your example -- a cut down version of it should be posted.
> Also use dput(obj), not str(obj) when posting so that the output
> is paste-able back into R.
>
> The use of zoo() is wrong in your pass.   zoo() accepts a
> numeric vector or matrix as arg 1 (or a factor) and a time index
> as arg 2 but you are passing a data frame as arg 1 and a data frame
> is not a numeric object.
>
> Read the three zoo vignettes and note the error here is covered
> in the FAQ:
>
> vignette("zoo-faq")
>
> Also note that there are numerous examples in the help files.  It
> would be better to take a little time and go through this rather than
> using trial and error without reference to the extensive documentation.
>
> On Thu, Dec 25, 2008 at 12:40 PM, zubin <binabina at bellsouth.net> wrote:
>   
>>> Okay, i think i solved the dates issue with your help, but hung up
>>> again...  My objective is to load this panel data set (cross sectional
>>> time series data) into a zoo object so i can use the time series
>>> functions(like arima, spectrum, etc..) and the quantmod library.
>>> However, it seems you can't have panel data in these objects, only
>>> multivariate time series (basically not data that is stacked or
>>> pooled, so there are multiple dates by cross-section unit).   So what
>>> i do is load the zoo object by store id#, which is okay - see below.
>>> I can convert to zoo, then when i try to utilize problems occur.  Zoo
>>> object converts all my integer data to character, i think??
>>>
>>>
>>>       
>>>> setwd("c:/csv")
>>>> d1 <- read.csv("baseline.csv",stringsAsFactors=FALSE)
>>>> dsmall <-
>>>>         
>>> subset(d1[,c('total_Cases','date','Store_nbr')],Store_nbr=='177')
>>>       
>>>> dsmall$z <- as.Date(dsmall$date, "%d%b%Y")
>>>> dsmallna <- na.omit(dsmall)
>>>> dsmallna$date <- NULL
>>>> str(dsmallna)
>>>>         
>>> 'data.frame':    414 obs. of  3 variables:
>>>  $ total_Cases: int  246 6502 5718 6234 853 6387 9833 6138 2405 8066 ...
>>>  $ Store_nbr  : int  177 177 177 177 177 177 177 177 177 177 ...
>>>  $ z          :Class 'Date'  num [1:414] 13770 13771 13772 13773 13774 ...
>>>  - attr(*, "na.action")=Class 'omit'  Named int [1:92] 415 416 417 418
>>> 419 420 421 422 423 424 ...
>>>   .. ..- attr(*, "names")= chr [1:92] "415" "416" "417" "418" ...
>>>
>>> this looks fine, the data.frame - total_Cases is variable of interest
>>> and its an integer.
>>>
>>>       
>>>> dzoo <- zoo(dsmallna, dsmallna$z)
>>>> str(dzoo)
>>>>         
>>> 'zoo' series from 2007-09-14 to 2008-10-31
>>>   Data: chr [1:414, 1:3] "  246" " 6502" " 5718" " 6234" "  853" ...
>>>  - attr(*, "dimnames")=List of 2
>>>   ..$ : chr [1:414] "1" "2" "3" "4" ...
>>>   ..$ : chr [1:3] "total_Cases" "Store_nbr" "z"
>>>   Index: Class 'Date'  num [1:414] 13770 13771 13772 13773 13774 ...
>>>
>>> /*okay, i don't know how to interpret the structure of the zoo object,
>>> Data: chr?  seems like it shifted to character? */ /*How does one
>>> interpret this object - $ : chr, $ : chr? */
>>>
>>> Now lets see if i can use the zoo object for some time series work...
>>> Nope all these errors, i think related to the character conversion the
>>> zoo object has done?
>>>
>>>       
>>>> plot(dzoo)
>>>>         
>>> i get a plot of total_Cases and store number and these errors?
>>>
>>> Error in plot.window(...) : need finite 'ylim' 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
>>>
>>>
>>>       
>>>> chartSeries(dzoo)
>>>>         
>>> Error in checkSlotAssignment(object, name, value) : assignment of an
>>> object of class "character" is not valid for slot "yrange" in an
>>> object of class "chob"; is(value, "numeric") is not TRUE
>>>
>>>
>>>       
>>>> acf(dzoo)
>>>>         
>>> Error in acf(dzoo) : 'x' must be numeric
>>>
>>>
>>> -zubin
>>>
>>>
>>>
>>>       
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>>     
>
>



More information about the R-SIG-Finance mailing list