[R] `its' questions

Ajay Shah ajayshah at mayin.org
Fri Aug 27 12:38:40 CEST 2004

Problem 1: Often, when I'm dealing with its, str() breaks. Here's a
bug demo. The first statements work fine --


  # Make a series of all dates from 1/1/2000 to 10/1/2000; fill this up
  # with integers from 1 to 30
  x1 <- newIts(start="2000-01-01", end="2000-01-10", 1:30, ncol=3)
  # Do the same, but restrict yourself to weekdays only
  x2 <- newIts(start="2000-01-01", end="2000-01-10", 1:30, ncol=3,
    extract=T, weekday=T)

  str(x1)    # works

But here it breaks --
  > str(x2)
  Error in object[1:ile] : subscript out of bounds

Problem 2: I try to write an its out and read it back in, but the two
don't seem to be conformable for matrix subtraction.

  # Let's try writing and reading --
  writecsvIts(x1, filename="/tmp/try.1")
  y <- its(readcsvIts(filename="/tmp/try.1"))

But this breaks --
  > y-x1
  Error in y - x1 : dates must match

(But they are identical, as the print commands show. x1 was written
out and read back into y).

Problem 3: How would I convert an its object into an ordinary
  numerical matrix or data frame? I have succeeded with statements
  like x <- as.numeric(itsobject[,2]) which extracts the 2nd
  column. But this 'wastes' the dates. How do I make a data frame out
  of the its object, where one of the columns is the dates? How do I
  make a matrix out of the its object, so that I don't have to attack
  one vector at a time using as.numeric() as shown above?

Problem 4: I tried to do plot() and then lines() but that does not
  seem to work. How does one superpose multiple curves on one picture,
  where each of them is an its object?

I will be most happy if someone can point me to more knowledge on
its. It seems like a fascinating library but I'm not yet able to learn
it using the standard docs.

Ajay Shah                                                   Consultant
ajayshah at mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi

More information about the R-help mailing list