hi, during a for(i in 1:xx]) loop I always newly calculate a vector (e.g. tmp<-c(a,b,c,d,e) ) now i need that vector to be attached at the bootom of a matrix (or data.frame). e.g. m<-matrix() for(i in 1:5]){ #some calculations for a,b,c,d,e a<- ... b<- ... c<- .. .... tmp<-c(a,b,c,d,e) ??? now I need to attach this tmp to the matrix m ??? } i couldn't get rbind or append to work properly thanks for advice, jan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
use list and do.call: MyList <- list() for(i in 1:5]){ #some calculations for a,b,c,d,e a<- ... b<- ... c<- .. .... MyList[[i]] <- c(a,b,c,d,e) } MyData <- do.call("rbind", MyList) will work fro relatively small ( < 1000, say) values of i. Otherwise, other solutions will be quicker. Best, Renaud Jan Malte Wiener wrote:> > hi, > > during a for(i in 1:xx]) loop I always newly calculate a vector > (e.g. tmp<-c(a,b,c,d,e) ) > now i need that vector to be attached at the bootom of a matrix (or > data.frame). > > e.g. > > m<-matrix() > > for(i in 1:5]){ > #some calculations for a,b,c,d,e > a<- ... b<- ... c<- .. .... > > tmp<-c(a,b,c,d,e) > > ??? now I need to attach this tmp to the matrix m ??? > } > > i couldn't get rbind or append to work properly > > thanks for advice, > jan > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Dr Renaud Lancelot, v?t?rinaire CIRAD, D?partement Elevage et M?decine V?t?rinaire (CIRAD-Emvt) Programme Productions Animales http://www.cirad.fr/presentation/programmes/prod-ani.shtml (Fran?ais) http://www.cirad.fr/presentation/en/program-eng/prod-ani.shtml (English) ISRA-LNERV tel (221) 832 49 02 BP 2057 Dakar-Hann fax (221) 821 18 79 (CIRAD) Senegal e-mail renaud.lancelot at cirad.fr -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
a brute force solution would be tmp<-c() for(i in 1:5]){ #some calculations for a,b,c,d,e a<- ... b<- ... c<- .. .... tmp<-c(tmp,c(a,b,c,d,e))} m<-t(matrix(tmp,5,5)) Jan Malte Wiener wrote:> hi, > > during a for(i in 1:xx]) loop I always newly calculate a vector > (e.g. tmp<-c(a,b,c,d,e) ) > now i need that vector to be attached at the bootom of a matrix (or > data.frame). > > > e.g. > > m<-matrix() > > for(i in 1:5]){ > #some calculations for a,b,c,d,e > a<- ... b<- ... c<- .. .... > > tmp<-c(a,b,c,d,e) > > ??? now I need to attach this tmp to the matrix m ??? > } > > i couldn't get rbind or append to work properly > > thanks for advice, > jan > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ > > >-- -- Erich Neuwirth, Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-38624 Fax: +43-1-4277-9386 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._