Re: [Rd] How to put my class into data.frame

From: Ferdinand Alimadhi <>
Date: Sat 04 Nov 2006 - 00:54:29 GMT

tmp$comp <- x@ratios ?!

Gregor Gorjanc wrote:

>I am developing a composition class, which represents a composition of
>mixture of levels, say soil has three components and each component
>accounts for 1/3 of the unit. I have tried with S4 class system and I
>would appreciate any help here. I was hoping that I would be able to
>include instance of my class into a data.frame. However, I encounter
>Simple definition of class could be
> representation=representation(ratios="matrix"))
>n <- 2
>k <- 3
>x <- new(Class="composition", ratios=matrix(data=rep(x=1/3, times=n*k),
>nrow=n, ncol=k))
>An object of class "composition"
>Slot "ratios":
> [,1] [,2] [,3]
>[1,] 0.3333333 0.3333333 0.3333333
>[2,] 0.3333333 0.3333333 0.3333333
>tmp <- data.frame(id=1:2)
>tmp$comp <- x
>Error: object is not subsettable
>As I understand this, my problem is that x is of length 1 as the
>following works
>tmp$comp <- c(x, x)
>although I am not able to print tmp now
>Error in unlist(x, recursive, use.names) :
> argument not a list
>but this is expected as I (probably) need show/print method for this.
>How can I put my class into data.frame or how can I make my class behave
>as a vector?


Ferdinand Alimadhi
Programmer / Analyst
Harvard University
The Institute for Quantitative Social Science
(617) 496-0187

______________________________________________ mailing list
Received on Sat Nov 04 12:04:36 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 04 Nov 2006 - 01:30:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.