Say you have a vector named x and a function which returns the character
string "x" . How would I take "x" as an input and return
the vector x?
DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}
Hi,
see ? as.numeric
as.numeric(c("-.1"," 2.7 ","-1.5"))
[1] -0.1 2.7 -1.5
you wrote:
Say you have a vector named x and a function which
returns the character
string "x" . How would I take "x" as an input and
return the vector x?
====Diventare costruttori di soluzioni
Became solutions' constructors
"The business of the statistician is to catalyze
the scientific learning process."
George E. P. Box
Visitate il portale http://www.modugno.it/
e in particolare la sezione su Palese
http://www.modugno.it/archivio/cat_palese.shtml
get("x") see also r-FAQ 7.21
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Apoian, Zack" <Zack.Apoian at sac.com>
To: "'R-help at lists.R-project.org'" <R-help at
stat.math.ethz.ch>
Sent: Wednesday, November 17, 2004 4:48 PM
Subject: [R] referencing values of strings
> Say you have a vector named x and a function which returns the
> character
> string "x" . How would I take "x" as an input and
return the vector
> x?
>
>
> DISCLAIMER: This e-mail message and any attachments are
> inte...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
On Wed, 17 Nov 2004, Apoian, Zack wrote:> Say you have a vector named x and a function which returns the character > string "x" . How would I take "x" as an input and return the vector x??get -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
"get" is your friend: R> x <- c( 1, 2, 3 ) R> get( "x" ) [1] 1 2 3 All the best, Arne On Wednesday 17 November 2004 16:48, Apoian, Zack wrote:> Say you have a vector named x and a function which returns the character > string "x" . How would I take "x" as an input and return the vector x? > > > DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html-- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de http://www.uni-kiel.de/agrarpol/ahenningsen/
On Wed, Nov 17, 2004 at 10:48:46AM -0500, Apoian, Zack wrote:> Say you have a vector named x and a function which returns the character > string "x" . How would I take "x" as an input and return the vector x?get("x") See ?get. You may also be interested in ?assign. + seth
Can you give some hypothetical code on what you want to do? Does get() do what you want:> dog <- "Spot" > f <- function(x) get(x) > f("dog")[1] "Spot" ? Andy> From: Apoian, Zack > > Say you have a vector named x and a function which returns > the character > string "x" . How would I take "x" as an input and return the > vector x? > > > DISCLAIMER: This e-mail message and any attachments are > inte...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
On Wed, 2004-11-17 at 10:48 -0500, Apoian, Zack wrote:> Say you have a vector named x and a function which returns the character > string "x" . How would I take "x" as an input and return the vector x?If I am understanding you correctly: x <- 1:10> x[1] 1 2 3 4 5 6 7 8 9 10 x.char <- "x"> get(x.char)[1] 1 2 3 4 5 6 7 8 9 10 See ?get for more information. HTH, Marc Schwartz
Vito Ricci wrote:> Hi, > > see ? as.numeric > > as.numeric(c("-.1"," 2.7 ","-1.5")) > [1] -0.1 2.7 -1.5 > > you wrote: > > Say you have a vector named x and a function which > returns the character > string "x" . How would I take "x" as an input and > return the vector x?I think the question might have been about obtaining the value of the symbol "x", in which case the answer is get("x")