Hello I would like to ask you if I can use the same method but for functions. That means that I want not to assign some value but a function. So is it possible to try something like that:
for (i in 1:10) for (j in 1:10) assign(paste("var",i,j,sep=""),myfunction) I would like to thank you in advance for your help best Regards Alexandros --- On Thu, 2/3/11, Eik Vettorazzi <e.vettora...@uke.uni-hamburg.de> wrote: > From: Eik Vettorazzi <e.vettora...@uke.uni-hamburg.de> > Subject: Re: [R] looping variable names > To: "hypermonkey22" <jonmo...@gmail.com> > Cc: r-help@r-project.org > Date: Thursday, February 3, 2011, 10:34 AM > As Greg wrote, a list is in most > circumstances a better way to store > many objects. > But you can use 'assign' and 'get' to create and access > (global) variables > > #creation > for (i in 1:100) assign(paste("var",i,sep=""),rnorm(5)) > > #access i-th variable > i<-15 > get(paste("var",i,sep="")) > > hth. > > Am 02.02.2011 21:36, schrieb hypermonkey22: > > > > Hi all, > > > > I've been looking for a simple answer to the following > problem. > > > > Let's say that I can loop through, say, 100 values > that need to be assigned > > to, say, the variables var1:var100. > > > > Is there an elegant way to do this? > > > > I have seen one or two similar questions...but they > tend to be in more > > complicated contexts. > > Simple question, hopefully with a simple answer. > > > > Thanks very much! > > > -- > Eik Vettorazzi > Institut für Medizinische Biometrie und Epidemiologie > Universitätsklinikum Hamburg-Eppendorf > > Martinistr. 52 > 20246 Hamburg > > T ++49/40/7410-58243 > F ++49/40/7410-57790 > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.