Re: [R] how to use different variable to store values with different length in a loop

From: jim holtman <jholtman_at_gmail.com>
Date: Fri, 18 Jan 2008 22:57:05 -0500

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?

______________________________________________
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.
Received on Sat 19 Jan 2008 - 04:01:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 19 Jan 2008 - 07:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive