Dear list I have a simple question that I have a mental block on: Having used a loop (from i = 1 to n) to assign some numerical values to row.list[[i]] e.g. row.list[[3]]= 0 1 I am wanting to combine the output into a simple matrix. for example, if I combine the output from persons 1 to 3 into a matrix, I thought I could do : h<-rbind(row.list[[1]]:row.list[[3]]) However, I get the errors: 1: Numerical expression has 2 elements: only the first used in: row.list[[1]]:row.list[[3]] Yet if I did this by using h< -rbind(row.list[[1]],row.list[[2]],row.list[[3]]), this would work. Could anybody explain how I can combine large values of the vectors (i.e. by using :) without resorting to having to write out each one in the command? Many thanks Laura -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Bayesianbay at aol.com wrote:> > Dear list > > I have a simple question that I have a mental block on: > > Having used a loop (from i = 1 to n) to assign some numerical values to > row.list[[i]] > e.g. row.list[[3]]= 0 1 > I am wanting to combine the output into a simple matrix. > > for example, if I combine the output from persons 1 to 3 into a matrix, I > thought I could do : > h<-rbind(row.list[[1]]:row.list[[3]]) > > However, I get the errors: > 1: Numerical expression has 2 elements: only the first used in: > row.list[[1]]:row.list[[3]] > > Yet if I did this by using h< > -rbind(row.list[[1]],row.list[[2]],row.list[[3]]), this would work. > > Could anybody explain how I can combine large values of the vectors (i.e. by > using :) without resorting to having to write out each one in the command?I think you may want do.call("rbind", row.list) Cheers, Jonathan. -- Jonathan Rougier Science Laboratories Department of Mathematical Sciences South Road University of Durham Durham DH1 3LE tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388 http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Laura, if all your vectors are of the same length, you can simply make a data.frame from your list and then you can easily construct submatrices by the usual subsetting methods. E.g.: data <- as.data.frame(row.list) # Here you have a data.frame with your rows as variables h <- as.matrix(t(data[,1:3])) # this should be the matrix you wanted in your example But if you need your data as matrix, you might like to construct it straight away: mat <- matrix(nrow=n,ncol=k) for(i in 1:n) mat[i,]<-rnorm(k) Hope this helps, Winfried --------------------------------------------------------------------- E-Mail: Winfried Theis <theis at statistik.uni-dortmund.de> Date: 10-Sep-02 Dipl.-Math. Winfried Theis SFB 475, Fachbereich Statistik, Universit"at Dortmund, 44221 Dortmund Tel.: +49-231-755-5903 FAX: +49-231-755-4387 ---------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._