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

From: Kaom Te <te.kaom_at_gmail.com>
Date: Sat, 12 May 2007 09:27:54 -0700


-----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-----



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 12 May 2007 - 16:33:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 May 2007 - 17:31:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.