I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly.
You want to use list: a = list() a[[1]] = c(1,2,3) a[[2]] = c(1,2,3) Note the [[..]] operator - check the "An Introduction to R" manual for more details Schalk Heunis On Wed, Sep 9, 2009 at 6:00 AM, <sclarke3 at illinois.edu> wrote:> I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly. > > ______________________________________________ > 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. >
The code below seems to contradict your claim that vectors cannot contain vectors.> zz <- vector(mode = "list", length = 3) > zz[[1]] NULL [[2]] NULL [[3]] NULL Best, Giovanni> Date: Tue, 08 Sep 2009 23:00:54 -0500 (CDT) > From: sclarke3 at illinois.edu > Sender: r-help-bounces at r-project.org > Precedence: list > > I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly. > > ______________________________________________ > 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. > >-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/