[R] get() with complex objects?

Mark Orr mo2259 at columbia.edu
Fri Jul 27 17:52:07 CEST 2007


Hello R-listers,
I'm having trouble accessing "sub" objects ("attributes"?), e.g., 
"x$silinfo$avg.width" using the /get() /command;  I'm using/ get()/ in a 
loop as illustrated in the following code:

#FIRST MAKE CLUSTERS of VARYING  k
/for (i in 1:300){
  assign(paste("x.",i,sep=""),pam(x,i))  #WORKS FINE
}/

#NEXT, TAKE LOOK AT AVE. SILHOUETTE VALUE FOR EACH k

#PART 1, MAKE LIST OF OBJECTS NEEDED
/gen.list <- rep("t",300)
for (i in 1:300){
  assign(gen.list[i],paste("x.",i,"$silinfo$avg.width",sep=""))
}
#WORKS FINE

/#PART 2, USE LIST IN LOOP TO ACCESS OBJECT.
/si//l.collector <- rep(99,300)
for(i in 1:300){
 sil.collector <- get(gen.list[i])
}/
#HERE IS THE ERROR
/Error in get(x, envir, mode, inherits) : variable 
"x.1$silinfo$avg.width" was not found

/So, I get the gist of this error; x.1 is an object findable from get(), 
but the "attribute"  levels are not accessible.  Any suggestions on how 
to get get() to access these levels?  From reading the get()'s help 
page, I don't think it will access the attributes. (my apologies for 
loosely using the term attributes, but I hope it is clear).

Thanks,

Mark Orr

-- 
***********************************************
Mark G. Orr, PhD
Heilbrunn Dept. of Population and Family Health
Columbia University
60 Haven Ave., B-2
New York, NY 10032

Tele: 212-304-7823
Fax:  212-305-7024

www.columbia.edu/~mo2259



More information about the R-help mailing list