[tech-spec] Re: R-data objects

  • From: Dirk Eddelbuettel <edd@xxxxxxxxxx>
  • To: tech-spec@xxxxxxxxxxxxx
  • Date: Mon, 11 Oct 2004 18:47:17 -0500

I _really_ shouldn't speak/email about this given how little I know or
understand about, but heck, one-eyed/blind/king and all that.

There are so-called S3 and S4 objects, named after the 'revisions' of the S
language. There are corresponding books by Chambers on it too.

On Mon, Oct 11, 2004 at 03:57:17PM -0700, BBands wrote:
> Version one:
> getDf <- function(file) {
>   Xdata <- read.csv(file, row.names=1)
>   revInd <- seq(NROW(Xdata),1)
>   invisible(Xdata[revInd,])
> }
> 
> IBM <- getDf("ibm.csv")

(This missed the command that actually created ibm.csv).

Here is a clue:

> class(IBM)
[1] "data.frame"

> Version two:
> 
> getYahoo <- function(symbol) {
>     Xdata <- priceIts(instrument = symbol, start = "2004-01-01", 
>     quote = c("Open", "High", "Low", "Close", "Volume", "Adj..Close."))
> }
> 
> require(its)
> IBM2 <- getYahoo("IBM")
> names(IBM2) <- c("Open", "High", "Low", "Close", "Volume", "Adj..Close.") 
>
> The resulting objects look the same except for the date format, but they are
> different???

Whereas:

> class(IBM2)
[1] "its"
attr(,"package")
[1] "its"
> 

but using the (undocumented ?) core() function of its:

> class(core(IBM2))
[1] "matrix"

from which you can transform into a data.frame:

> class(data.frame(core(IBM2)))
[1] "data.frame"

So now IBM and IBM2 could be the same, if the start & end dates are aligned
etc pp.

> Data file attached.

It wasn't, due the amount of malware around:

> -- Binary/unsupported file stripped by Ecartis --
> -- Type: application/octet-stream
> -- File: IBM.csv
 
Obviously a bug in Ecartis.
 
Dirk 

-- 
Those are my principles, and if you don't like them... well, I have others.
                                                -- Groucho Marx

Other related posts: