Hello, I have trouble converting a character string to a R object. Let me describe this by an example;> dim(a)[1] 270 14> dim("a")NULL> names(a)[1] "Var1" "Var2" "Var3" "Var4" "Var5" "Var6" "Var7" "Var8" "Var9" [10] "Var10" "Var11" "Var12" "Var13" "Var14"> names("a")NULL I realise that the character string lacks both a dimension and any column names; my question is how to make R understand that I look for the object a when I write "a". Like a type cast in C; (R data.frame) "a" for those familiar with C. The underlying reason for this is that I am writing a script that imports several datasets. The file names of the datasets contain the '_' character which forces me to construct a valid dataset name for each file. Although I can do this by hand, I would like to know if there is any solution to my first approach. Thanks in advance, Sixten Sixten Borg IHE Box 2127 S-220 02 Lund Sweden tel: +46 46 32 91 07 fax:+46 46 12 16 04 www.ihe.se ******************************************************************* Note: The information contained in this message and attachments may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. IHE
Please do use a meaningful subject line.
You are looking for get(): get("a") returns the R object named
"a" (if one
is in scope).
Note that if you use R-devel (the development version of R, see the FAQ)
you _can_ use underscore in object names.
On Thu, 8 Jan 2004, Sixten Borg wrote:
> I have trouble converting a character string to a R object. Let me
> describe this by an example;
>
> > dim(a)
> [1] 270 14
> > dim("a")
> NULL
>
> > names(a)
> [1] "Var1" "Var2" "Var3" "Var4"
"Var5" "Var6" "Var7" "Var8"
"Var9"
> [10] "Var10" "Var11" "Var12"
"Var13" "Var14"
> > names("a")
> NULL
>
> I realise that the character string lacks both a dimension and any
> column names; my question is how to make R understand that I look for
> the object a when I write "a".
>
> Like a type cast in C; (R data.frame) "a" for those
familiar with C.
Rather, more like following a pointer in C. A cast would be
as.data.frame("a") or as("a", "data.frame"),
which is not what you want.
> The underlying reason for this is that I am writing a script that
> imports several datasets. The file names of the datasets contain the
'_'
> character which forces me to construct a valid dataset name for each
> file. Although I can do this by hand, I would like to know if there is
> any solution to my first approach.
--
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