[R] How to Derive an S4 Class from a data.frame?

Kaom Te te.kaom at gmail.com
Sat May 12 18:27:54 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello R-Help:

I would really appreciate some help on this. I have spent a good deal of
time searching for an answer for what I would think to be a common
practice: Subclasses an S4 class from a data.frame. But have found very
little.

Here is some sample code that I've been trying:

setClass("MyDataFrame",
         representation("data.frame",
                        mysize = "numeric"))

new("MyDataFrame",
    data.frame(col1 = c(1,2,3),
               col2 = c("four", "five", "six")),
    mysize = 12)


When I run this in R 2.3.1(Windows XP) I get this

> setClass("MyDataFrame",
+          representation("data.frame",
+                         mysize = "numeric"))
[1] "MyDataFrame"
> new("MyDataFrame",
+     data.frame(col1 = c(1,2,3),
+                col2 = c("four", "five", "six")),
+     mysize = 12)
An object of class "MyDataFrame"
NULL data frame with 0 rows
Slot "mysize":
[1] 12

>
>

Anyone have any suggestions?

Regards,
Kaom Te
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGResKaaZgZdCbWv4RAh9mAJ9O+PWekZDtqhhyoCn64Di5IWZvgACfQqW4
apYvfKs8OVnn5tkq867pgKQ=
=EP0J
-----END PGP SIGNATURE-----



More information about the R-help mailing list