Dear R users, That's probably a silly question even for a newbie but : Is it possible to assign variable prices as variable names ? For instance, would something like the following work : for (i in 1:4) { error.i <- some_calculation } so "error.i" variables would be created for i=1,2,3,4 i.e. error.1 error.2 error.3 etc. etc. Costas -- --------------------------------------------------------------------- Konstantinos E. Vorloou | Tel: +44 (0)191 374 1821 Dept. of Economics & Finance | Fax: +44 (0)191 374 7289 University of Durham, | email: K.E.Vorloou at durham.ac.uk 23/26 Old Elvet, | or : vorlow at rocketmail.com Durham DH1 3HY, | --------------------------------- UK. | http://www.durham.ac.uk/~dec3kev http://www.durham.ac.uk/Economics | ICQ: 20595534 --------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 17 Feb 1999, Konstantinos Euripides Vorloou wrote:> Dear R users, > > That's probably a silly question even for a newbie but : > > Is it possible to assign variable prices as variable names ? > For instance, would something like the following work : > > for (i in 1:4) > { > error.i <- some_calculation > }It's possible but difficult and probably not what you want. You can do something like assign(paste("error",i,sep="."),some.calculation) but it's much easier to use a vector: error<-numeric(4) for (i in 1:4) { error[i]<-some.calculation } Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
for(i in 1:4){ eval(parse(text=paste("error.",i," <- i ",sep=""))) }> error.1[1] 1> error.2[1] 2> error.3[1] 3> error.4[1] 4>(but wouldn't a vector of length 4 be more convenient ....?) Jonathan --------------------- Date: Wed, 17 Feb 1999 17:07:43 +0000 From: Konstantinos Euripides Vorloou <K.E.Vorloou at durham.ac.uk> Organization: Dept. of Economics - University of Durham (UK) X-Accept-Language: en,el Content-Type: text/plain; charset=iso-8859-7 Sender: owner-r-help at stat.math.ethz.ch Precedence: bulk Dear R users, That's probably a silly question even for a newbie but : Is it possible to assign variable prices as variable names ? For instance, would something like the following work : for (i in 1:4) { error.i <- some_calculation } so "error.i" variables would be created for i=1,2,3,4 i.e. error.1 error.2 error.3 etc. etc. Costas -- --------------------------------------------------------------------- Konstantinos E. Vorloou | Tel: +44 (0)191 374 1821 Dept. of Economics & Finance | Fax: +44 (0)191 374 7289 University of Durham, | email: K.E.Vorloou at durham.ac.uk 23/26 Old Elvet, | or : vorlow at rocketmail.com Durham DH1 3HY, | --------------------------------- UK. | http://www.durham.ac.uk/~dec3kev http://www.durham.ac.uk/Economics | ICQ: 20595534 --------------------------------------------------------------------- -- Dr. Jonathan Myles e-mail:jonathan.myles at mrc-bsu.cam.ac.uk MRC Biostatistics Unit Tel. 01223 330371 Institute of Public Health FAX 01223 330388 University Forvie Site Robinson Way CAMBRIDGE CB2 2SR -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Konstantinos Euripides Vorloou <K.E.Vorloou at durham.ac.uk> writes:> Dear R users, > > That's probably a silly question even for a newbie but : > > Is it possible to assign variable prices as variable names ? > For instance, would something like the following work : > > for (i in 1:4) > { > error.i <- some_calculation > } > > so "error.i" variables would be created for i=1,2,3,4 > i.e. error.1 error.2 error.3 etc. etc.Yes. Look at the help page for assign(). Whether it is ever better than using arrays or lists is questionable, though. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._