[R] two dimensional array of object elements
Gabor Grothendieck
ggrothendieck at myway.com
Fri Feb 11 21:15:51 CET 2005
Weijie Cai <wcai11 <at> hotmail.com> writes:
:
: Hi list,
:
: I want to create a two (possibly three) dimensional array of objects. These
: objects are classes in object oriented style. I failed by using
: a<-array(NA,c(m,n))
: for (i in 1:m){
: for (j in 1:n){
: a[i,j]<-My.Obj
: }
: }
:
A list that has a dim attribute should do it:
R> x <- list(12, "abc", 3i, sin)
R> dim(x) <- c(2,2)
R> x
[,1] [,2]
[1,] 12 0+3i
[2,] "abc" ?
R> x[[2,2]](pi/180)
[1] 0.01745241
More information about the R-help
mailing list