moritz.marienfeld at arcor.de
2006-Mar-28 08:54 UTC
[R] How to generate a list of lists recursively (for bayesm)
Dear all, I need to generate a list of lists as required by the bayesm-package. This means in my application that I have to generate a list which consists of 2000 elements, which are lists themselves: list(list(y1,X1),...,list(y2000,X2000)). The y are vectors and the X are matrices of different dimensions. I tried to solve this problem iteratively by the following code, but received an error message, which I do not understand:> for(i in 1:1067){+ c<-0 + for(j in 1:300){ + if(Sk[i,j]!=0){ + c<-c+1 + if(c==1){ + X1<-att[j,] + X2<-attq8[j,] + y<-Sk[i,j] + } + else{ + X1<-rbind(X1,att[j,]) + X2<-rbind(X2,attq8[j,]) + y<-rbind(y,Sk[i,j]) + } + }} + regdata1[[c(i,1)]]<-y + regdata1[[c(i,2)]]<-X1 + regdata2[[c(i,1)]]<-y + regdata2[[c(i,2)]]<-X2 + } Fehler: objekt "regdata1" nicht gefunden ??? So, does anybody know what I did wrong or how I can generate my list of lists? Regards, Moritz Moritz Marienfeld Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 44,85 ? inkl. DSL- und ISDN-Grundgeb?hr!
Jacques VESLOT
2006-Mar-28 09:54 UTC
[R] How to generate a list of lists recursively (for bayesm)
1) see in ?"[[": "The most important distinction between '[', '[[' and '$' is that the '[' can select more than one element whereas the other two select a single element." 2) what are Sk, att, attq8, regdata1 and regdata2 ? moritz.marienfeld at arcor.de a ?crit :>Dear all, > >I need to generate a list of lists as required by the bayesm-package. This means in my application that I have to generate a list which consists of 2000 elements, which are lists themselves: > >list(list(y1,X1),...,list(y2000,X2000)). > >The y are vectors and the X are matrices of different dimensions. I tried to solve this problem iteratively by the following code, but received an error message, which I do not understand: > > > > >>for(i in 1:1067){ >> >> >+ c<-0 >+ for(j in 1:300){ >+ if(Sk[i,j]!=0){ >+ c<-c+1 >+ if(c==1){ >+ X1<-att[j,] >+ X2<-attq8[j,] >+ y<-Sk[i,j] >+ } >+ else{ >+ X1<-rbind(X1,att[j,]) >+ X2<-rbind(X2,attq8[j,]) >+ y<-rbind(y,Sk[i,j]) >+ } >+ }} >+ regdata1[[c(i,1)]]<-y >+ regdata1[[c(i,2)]]<-X1 >+ regdata2[[c(i,1)]]<-y >+ regdata2[[c(i,2)]]<-X2 >+ } >Fehler: objekt "regdata1" nicht gefunden > >??? So, does anybody know what I did wrong or how I can generate my list of lists? > >Regards, > >Moritz > >Moritz Marienfeld > >Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren >ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig >und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, >nur 44,85 ? inkl. DSL- und ISDN-Grundgeb?hr! > >______________________________________________ >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 > > >
v.schlecht at arcor.de
2006-Mar-28 12:39 UTC
[R] How to generate a list of lists recursively (for bayesm)
thanx for the reply. Sk is a 1067*300 matrix att is a 300*15 matrix attq8 is a 300*17 matrix regdata1 and regdata2 are meant to become my 2 lists of lists by this procedure - I actually do not know if they should be initialized in any other way as lists of lists and how to do this. Moritz Marienfeld Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 44,85 ? inkl. DSL- und ISDN-Grundgeb?hr! Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 44,85 ? inkl. DSL- und ISDN-Grundgeb?hr!
Michael Dondrup
2006-Mar-28 14:46 UTC
[R] How to generate a list of lists recursively (for bayesm)
Hi Moritz, you need to initialize your lists somehow, before you can use them (hence the error) like:> regdata1 <- regdata2 <- list()[some for loops] I believe it might be cleaner to use c() to concat the lists, as your code seems to add lists at the end, than to assign to list elements which do not actually exist. Cheers Am Tuesday 28 March 2006 14:39 schrieb v.schlecht at arcor.de:> thanx for the reply. > > Sk is a 1067*300 matrix > att is a 300*15 matrix > attq8 is a 300*17 matrix > regdata1 and regdata2 are meant to become my 2 lists of lists by this > procedure - I actually do not know if they should be initialized in any > other way as lists of lists and how to do this. > >