Friday, 9 August 2013

Can the paste() function produce values?

Can the paste() function produce values?

I dynamically generate 5 variables each containing a random value:
> i = 1
>
> while(i <= 5)
{
assign(paste("x", i, sep = ""), rnorm(1))
i = i + 1
}
> x1
[1] 0.3853609
> x2
[1] 1.626055
> x3
[1] -1.043699
> x4
[1] 0.3449921
> x5
[1] -0.9768416
Is there any function in R that will allow me to dynamically display the
value of each of the variables. What I mean is a function like:
> paste("x", 1, sep = "")
[1] "x1"
that would not produce a character string, but that would show the value
of the variable x1. In this way, I could create a loop to display all the
values.
Thanks for your help.

No comments:

Post a Comment