Skip to content

zoo plotting - invalid 'ylim' value

7 messages · Khanh Nguyen, Gabor Grothendieck, Spencer Graves +1 more

#
Hi all,

I am very new to 'zoo', so this could probably be a trivia question,
but I got the above error when I plot my zoo object
2009-05-28  2009-05-29  2009-06-01  2009-06-02  2009-06-03
2009-06-04  2009-06-05
11104740    10772400    10775110    10397160    10037930     9986480
 10003780
 2009-06-08  2009-06-09  2009-06-10  2009-06-11  2009-06-12
2009-06-15  2009-06-16
10163340    10545920    11020540    10720430    10484040    10502080
 10932930
 2009-06-17
11201700
Error in plot.window(...) : invalid 'ylim' value
Thanks

-k
#
What is the result of

dput(stb.foreign)
On Wed, Jun 17, 2009 at 1:53 PM, Khanh Nguyen<knguyen at cs.umb.edu> wrote:
#
Just to follow up the thread so that it is not left dangling
the problem was that the object in question had character
rather than numeric data in it.

On Wed, Jun 17, 2009 at 1:58 PM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote:
#
Hi, Gabor: 


      I just lost perhaps a day's work due to that very problem:  I 
couldn't get read.zoo to work, so I used read.table, which created 
factors, because some of my numeric columns included, ", NA", which got 
translated as a level " NA" (note this three character code with a space 
before the NA).  Then I did "as.matrix" of the data.frame that I thought 
was numeric;  the result was a zoo object with coredata of class 
character rather than numeric. 


      Best Wishes,
      Spencer
Gabor Grothendieck wrote:
#
Check out the na.strings= argument:
+ 4,6
+ 5, NA"
?zoo? series from 3 to 5
  Data: int [1:3] NA 6 NA
  Index:  int [1:3] 3 4 5
On Wed, Jun 17, 2009 at 10:43 PM, spencerg<spencer.graves at prodsyse.com> wrote:
#
Spencer,
On 17 June 2009 at 20:43, spencerg wrote:
|       I just lost perhaps a day's work due to that very problem:  I 
| couldn't get read.zoo to work, so I used read.table, which created 
| factors, because some of my numeric columns included, ", NA", which got 
| translated as a level " NA" (note this three character code with a space 
| before the NA).  Then I did "as.matrix" of the data.frame that I thought 
| was numeric;  the result was a zoo object with coredata of class 
| character rather than numeric. 

Very painful.

But that may be a good reminder that at the end of the day, almost all data
reading methods wrap around read.table --- i.e. read.csv "merely" sets the
separator option (and some others), read.zoo "merely" manages to set an index
option of appropriate type etc pp.   

Why does this matter?  Because read.table respect the (reasonably new) option
stringsAsFactors.  From ?read.table:

     read.table(file, header = FALSE, sep = "", quote = "\"'",
                dec = ".", row.names, col.names,
                as.is = !stringsAsFactors,
                        ^^^^^^^^^^^^^^^^^
[...]
                stringsAsFactors = default.stringsAsFactors(),
                fileEncoding = "", encoding = "unknown")

[...]

stringsAsFactors: logical: should character vectors be converted to
          factors?  Note that this is overridden bu 'as.is' and
          'colClasses', both of which allow finer control.


and from ?default.stringsAsFactors :


stringsAsFactors: logical: should character vectors be converted to
          factors?  The 'factory-fresh' default is 'TRUE', but this can
          be changed by setting 'options(stringsAsFactors = FALSE)'.


It may be worthwhile to set this option in ~/.Rprofile

Hth, Dirk
#
Or perhaps even better, colClasses = "numeric"
?zoo? series from 3 to 5
  Data: num [1:3] NA 6 NA
  Index:  num [1:3] 3 4 5


On Wed, Jun 17, 2009 at 10:58 PM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote: