If you want an easy way to change the name of the data frame for assignment
then you may want a macro.  There is an article in the R journal (
http://cran.r-project.org/doc/Rnews/Rnews_2001-3.pdf) on creating macros
and there are tools that help with creating macros in the gtools package.

Though what you are trying to do may work a little better using
`findInterval` or `merge`.


On Wed, Jun 12, 2013 at 2:36 PM, bcrombie <bcrom...@utk.edu> wrote:

> I'm adding a column (region) to a data frame (devUni8), and the (region)
> column will be populated by a numeric code that is a function of another
> column (state) in that data frame.  See part of the script below.
>
> How can I rewrite this so that I could apply the conditions to any data
> frame without having to keep typing its name (in this case, "devUni8$").
> I've heard the attach() function is to be avoided, and I'm not good at
> with,
> while, or if statements right now.  I've tried some other things but keep
> getting "object not found" errors.  Assistance appreciated. Thanks.
>
> #Create Region Variable
> #########
> devUni8$region=0
>
> #Assign Northeast States
> #########
> devUni8$region[devUni8$state >= 11 & devUni8$state <= 23 | devUni8$state >=
> 51 & devUni8$state <= 55] = 1
>
> #Assign Southeast States
> #########
> devUni8$region[devUni8$state >= 56 & devUni8$state <= 64 ] = 2
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/rewrite-script-to-eliminate-constant-object-reference-tp4669393.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to