Jack Luo
2008-Jan-19 03:28 UTC
[R] how to use different variable to store values with different length in a loop
Hi, List I am trying to use variables named A1, A2, ..., A100 to store some values, each variable could store some values with different length, how can I achieve this? Thanks, Jack [[alternative HTML version deleted]]
jim holtman
2008-Jan-19 03:57 UTC
[R] how to use different variable to store values with different length in a loop
I would recommend that you use a "list" instead of creating the variables. Here is how you might do a list: # preallocate the list myList <- vector('list', 100) for (i in 1:100){ .....you calculations..... myList[[i]] <- result } If you really want to create 100 variables, then use 'assign': for (i in 1:100){ .... your calculations.... assign(paste("A", i, sep=""), result) } But a 'list' is much easier to handle especially in that all the related data is in one object. On Jan 18, 2008 10:28 PM, Jack Luo <jluo.rhelp at gmail.com> wrote:> Hi, List > > I am trying to use variables named A1, A2, ..., A100 to store some values, > each variable could store some values with different length, how can I > achieve this? > > Thanks, > > Jack > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?