Dear All, How can I create a vector of vector in R? for example, I would input the data as follows: x[1] <- c(31,2,3) x[2] <- c(1,2,5,34,5656) x[3] <- c(211,3243,5,343,3) Jim Liu
You can create a list of vector. x <- list(c(31,2,3), c(1,2,5,34,5656), c(211,3243,5,343,3)) x[[1]] x[[2]] x[[3]] On Fri, Aug 8, 2008 at 2:59 PM, Jim <chunchiliu at gmail.com> wrote:> Dear All, > > How can I create a vector of vector in R? > for example, I would input the data as follows: > x[1] <- c(31,2,3) > x[2] <- c(1,2,5,34,5656) > x[3] <- c(211,3243,5,343,3) > > Jim Liu > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On 8/8/2008 1:59 PM, Jim wrote:> Dear All, > > How can I create a vector of vector in R? > for example, I would input the data as follows: > x[1] <- c(31,2,3) > x[2] <- c(1,2,5,34,5656) > x[3] <- c(211,3243,5,343,3)x <- list() x[[1]] <- c(31,2,3) x[[2]] <- c(1,2,5,34,5656) x[[3]] <- c(211,3243,5,343,3) Note the double brackets: x[[1]] is the thing stored in the first element of x; x[1] would be a length-1 list containing only the first element from the list x. Duncan Murdoch
is this what you want? x <- c(31,2,3) y <- c(1,2,5,34,5656) z <- c(211,3243,5,343,3) a <- list(x,y,z) On Fri, Aug 8, 2008 at 1:59 PM, Jim <chunchiliu at gmail.com> wrote:> Dear All, > > How can I create a vector of vector in R? > for example, I would input the data as follows: > x[1] <- c(31,2,3) > x[2] <- c(1,2,5,34,5656) > x[3] <- c(211,3243,5,343,3) > > Jim Liu > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Hi Jim, x<-as.vector(list(c(31,2,3), c(1,2,5,34,5656),c(211,3243,5,343,3)))> x[1][[1]] [1] 31 2 3> x[2][[1]] [1] 1 2 5 34 5656> x[3][[1]] [1] 211 3243 5 343 3 Hope this helps Chunhao Quoting Jim <chunchiliu at gmail.com>:> Dear All, > > How can I create a vector of vector in R? > for example, I would input the data as follows: > x[1] <- c(31,2,3) > x[2] <- c(1,2,5,34,5656) > x[3] <- c(211,3243,5,343,3) > > Jim Liu > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >