Re: [R] Paste and namespace

About this list Date view Thread view Subject view Author view Attachment view

From: Edith Hodgen (Edith.Hodgen@nzcer.org.nz)
Date: Tue 17 Jun 2003 - 11:57:46 EST


Message-id: <seef1e67.028@smtp.nzcer.org.nz>

This was discussed in

Date: 1/06/2003 06:00:32
Subject: Re: [R] parse on left hand side of R assignment

On Sat, 31 May 2003, Paul E. Johnson wrote:

> I keep finding myself in a situation where I want to calculate a
> variable name and then use it on the left hand side of an assignment.
> For example
>
> iteration <- 1
> varName <- paste("run",iteration,sep="")
> myList$parse(text=varName) <- aColumn
>
> I want to take some existing variable "aColumn" and use the name
> "varName" name for it and put it into a list "myList". That use fails
> with this error:
.... Snip

For a data frame you could use

mydf[paste("run",iteration,sep="")] <- aColumn

and for a list or a data frame

Robject[[paste("run",iteration,sep="")]] <- aColumn

=================================================
I don't remember if there was any more interesting discussion in the thread.

HTH
Edith

Edith Hodgen
Statistician and Data Manager
New Zealand Council for Educational Research
Phone: +64-4-384 7939 x 812
Fax: +64-4-384 7933
edith.hodgen@nzcer.org.nz

           Web site http://www.nzcer.org.nz

>>> Fernando Henrique Ferraz Pereira da Rosa <mentus@gmx.de> 17/06/2003 13:43:42 >>>
 Hi, my doubt is very simple. I'm sure I've seen someone using something
like this before, but unfortunatelly my searches in the archives were useless.
 Well, I have some objects called after a name that has a number attached to
it,
 varying. Let's say I have:
> ls
   poly1 poly2 poly3 poly4 poly5 poly6 ...
 
 I would like to access these objects using a for(), in which I could do
something like paste("poly",i,sep=''). For i = 4, for instance I get
> paste("poly",4,=sep'')
 [1] "poly8"
 Which is a string. What command should I use to 'access' the object named
by this string, ir order to do some useful things, like changing its value?

Thank you,

--

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:54 EST