Create your original matrix as a list datatype. When assigning elements, be careful with the list structure, as the example indicates.

> m <- 2; n <- 3
> a <- array(list(),c(m,n))
> a[1,2] <- list(b=1,c=2)
Error in "[<-"(`*tmp*`, 1, 2, value = list(b = 1, c = 2)) :
        number of items to replace is not a multiple of replacement length
> a[1,2] <- list(list(b=1,c=2))
>



At Friday 11:36 AM 2/11/2005, Weijie Cai wrote:
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
}
}


The elements are still NA. Any suggestions?

Thanks

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to