Hi, suppose I do: b <- matrix(1:9,3,3) bname <- "b" now dim(b) returns [1] 3 3 and dim(bname) returns NULL is there a function to pass bname to such that dim returns the dimensions of b? like dim(somefunc(bname)) returns [1] 3 3 does 'somefunc' exist? daver +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |David Richmond It works on a | + Dept. of Sociology complex scientific + |Saint Mary's College principle, known as | + Notre Dame, IN 46556 "pot luck." + |219-284-4517 - The Doctor | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
David A Richmond <richmond at saintmarys.edu> writes:> Hi, > suppose I do: > b <- matrix(1:9,3,3) > bname <- "b" > > now > dim(b) > returns > [1] 3 3 > > and > dim(bname) > returns > NULL > > is there a function to pass bname to such that dim returns the dimensions > of b? > > like > dim(somefunc(bname)) > returns > [1] 3 3 > > does 'somefunc' exist?get() -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 28 Sep 2001, David A Richmond wrote:> suppose I do: > b <- matrix(1:9,3,3) > bname <- "b" > > dim(bname) > returns > NULL > > is there a function to pass bname to such that dim returns the dimensions > of b? > > like > dim(somefunc(bname)) > returns > [1] 3 3> > does 'somefunc' exist?R> dim(eval(parse(text=bname))) [1] 3 3 --------------------------------------------------------------------------- Keith Richards-Dinger U.S. Geological Survey, MS-977 Office 1-650-329-5519 345 Middlefield Road Fax 1-650-329-5163 Menlo Park, CA USA 94025 e-mail dinger at usgs.gov --------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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, 28 Sep 2001, David A Richmond wrote: <snip>> is there a function to pass bname to such that dim returns the dimensions > of b? > > like > dim(somefunc(bname)) > returns > [1] 3 3 > > does 'somefunc' exist?As already pointed out, eval(parse(text=bname)) will return the object whose name is in the text string. Another way is get(bname), which is more specific (it gets objects by name, rather than evaluating arbitrary code). In general, this sort of question is frequently a sign that someone is doing things the hard way. There are some real situations where you need to operate on strings like this, but they are fairly rare. For example, if you have a collection of arrays and may want the dimensions of any one of them, you could put them in a list listofarrays<-list() listofarrays$b <- matrix(1:9,3,3) dim(listofarrays$b) and even bname<-"b" dim(listofarrays[[bname]]) -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._