[R] How to create multi variables
Yuanzhi Li
Yuanzhi.Li at USherbrooke.ca
Wed May 14 02:47:12 CEST 2014
Hi, everyone
I want to create a series of variables (e.g. t1, t2..., t10) which could
be used in loops. My idea is to use function "assign"
for (i in 1:10)
{
assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to
variable ti
}
But when I create a vector containing the names of these variables and
want to use the variables according to the subscript, it doesn't works.
t<-noquote(paste("t",1:10,sep=""))
t[1]
t1
it returns only the name of variable t1, but not the value allocated to
t1 by FUN. So what should I do to realize this?
Or is there any better way to do this?
Can we define a series of variables which can be used according to the
subscript like
t<-f(t1, t2..., t10),
then we have 10 variables which can be used directly?
for(i in 1:10)
{
t[i]<-FUN# with the fines variables we can directly assign the value
of FUN to ti
}
These are just my thoughts, I don't know whether there are available R
codes to realized it. I am looking forward any help from you.
Thanks in advance!
Yuanzhi
More information about the R-help
mailing list