Brian.J.GREGOR@odot.state.or.us
2002-May-24 19:45 UTC
[R] Converting Character Strings into Object Names
Is there a function to convert character strings to object references. For example, I want to name sets of objects based on scenarios and the types of data being stored. So the scenarios might be something like c("a", "b", "c"), the types of data might have names like c("pass.trp", "trk.trp", "cmute.trp"), and I want to assign data to the objects a.pass.trp, b.pass.trp, c.pass.trp, a.trk.trp, etc. I'd like to be able to paste the names together and then use them as an object references. Brian Gregor, P.E. Transportation Planning Analysis Unit Oregon Department of Transportation Brian.J.GREGOR at odot.state.or.us (503) 986-4120 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 Fri, 24 May 2002 Brian.J.GREGOR at odot.state.or.us wrote:> Is there a function to convert character strings to object references. For > example, I want to name sets of objects based on scenarios and the types of > data being stored. So the scenarios might be something like c("a", "b", > "c"), the types of data might have names like c("pass.trp", "trk.trp", > "cmute.trp"), and I want to assign data to the objects a.pass.trp, > b.pass.trp, c.pass.trp, a.trk.trp, etc. I'd like to be able to paste the > names together and then use them as an object references.Yes. The get() and assign() functions allow you to reference objects by character strings, and as.name() will convert a string into a reference (you would then probably need to use substitute() to create an expression and eval()) to evaluate it. eg assign("a",get("b")) does a<-b Often there is a better way: the objects can be stored in a list, making it possible to use character strings directly to reference them If obj<-list(a=1,b=2) then obj[["a"]] is a reference to the "a" element and you can do eg obj[["a"]]<-otherobj[["b"]] -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
White.Denis@epamail.epa.gov
2002-May-24 20:36 UTC
[R] Converting Character Strings into Object Names
> Is there a function to convert character strings to object > references. For example, I want to name sets of objects > based on scenarios and the types of data being stored. > So the scenarios might be something like c("a", "b", > "c"), the types of data might have names like c("pass.trp", > "trk.trp", "cmute.trp"), and I want to assign data to the > objects a.pass.trp, b.pass.trp, c.pass.trp, a.trk.trp, etc. > I'd like to be able to paste the names together and then > use them as an object references.For example, obj <- eval (parse (text=paste ("a", "pass.trp", sep=""))) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
?assign GP> Is there a function to convert character strings to object references. For > example, I want to name sets of objects based on scenarios and the types of > data being stored. So the scenarios might be something like c("a", "b", > "c"), the types of data might have names like c("pass.trp", "trk.trp", > "cmute.trp"), and I want to assign data to the objects a.pass.trp, > b.pass.trp, c.pass.trp, a.trk.trp, etc. I'd like to be able to paste the > names together and then use them as an object references. > > Brian Gregor, P.E. > Transportation Planning Analysis Unit > Oregon Department of Transportation > Brian.J.GREGOR at odot.state.or.us > (503) 986-4120-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________] -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._