Bob Green
2007-Mar-12 20:54 UTC
[R] altering prefix to multiple variables in different locations within a command file
Hello, I am seeking advice regarding how I might add the prefix " kc$ " to variables in a series of commands. The complication is that there is a large number of variables with different commands. Examples of the variables in typical commands follow. It is simple to use search & replace for common variables such as "group" but I would appreciate advice about whether there is a way to readily alter the remaining variables. Bob Green CrossTable(group,TOC2,chisq=TRUE,resid=TRUE, missing.include=FALSE) fisher.test(group,TOC2) tapply(TOC2, group, mean) tapply( TOC2, group, sd) oneway.test ( TOC2 ~ group, var.equal=FALSE) kruskal.test ( TOC2 ~ group) broadcast =="" broadcast [broadcast ==""] <- "n" CrossTable( group,broadcast ,chisq=TRUE,resid=TRUE, missing.include=FALSE) fisher.test(group,broadcast) jealous [jealous=="y (not victim)"] = "n" jealous=="" jealous [jealous==""] <- "n" jealous=="" CrossTable(group,jealous ,chisq=TRUE,resid=TRUE, missing.include=FALSE) fisher.test(group,jealous)
Charilaos Skiadas
2007-Mar-12 22:40 UTC
[R] altering prefix to multiple variables in different locations within a command file
On Mar 12, 2007, at 4:54 PM, Bob Green wrote:> Hello, > > I am seeking advice regarding how I might add the prefix " kc$ " to > variables in a series of commands. The complication is that there is > a large number of variables with different commands. Examples of the > variables in typical commands follow.Maybe I've misunderstood what you want to do, but would "with" meet the case? > a Error: object "a" not found > x<-list(a=5) > with(x,a) [1] 5 > x$a [1] 5 > See ?with> It is simple to use search & replace for common variables such as > "group" but I would appreciate advice about whether there is a way > to readily alter the remaining variables. > > Bob GreenHaris Skiadas Department of Mathematics and Computer Science Hanover College
Stephen Tucker
2007-Mar-12 23:03 UTC
[R] altering prefix to multiple variables in different locations within a command file
I think what you are looking for is attach()? attach(kc) # commands (don't need to prefix variables with "kc$") detach(kc) In this way an environment is created in which you can refer to the variables in your data frame without the "kc$" prefix. (see ?attach) --- Bob Green <bgreen at dyson.brisnet.org.au> wrote:> Hello, > > I am seeking advice regarding how I might add the prefix " kc$ " to > variables in a series of commands. The complication is that there is > a large number of variables with different commands. Examples of the > variables in typical commands follow. > > It is simple to use search & replace for common variables such as > "group" but I would appreciate advice about whether there is a way > to readily alter the remaining variables. > > Bob Green > > > CrossTable(group,TOC2,chisq=TRUE,resid=TRUE, missing.include=FALSE) > fisher.test(group,TOC2) > > tapply(TOC2, group, mean) > tapply( TOC2, group, sd) > > oneway.test ( TOC2 ~ group, var.equal=FALSE) > kruskal.test ( TOC2 ~ group) > > > broadcast =="" > broadcast [broadcast ==""] <- "n" > CrossTable( group,broadcast ,chisq=TRUE,resid=TRUE, > missing.include=FALSE) > fisher.test(group,broadcast) > > jealous [jealous=="y (not victim)"] = "n" > jealous=="" > jealous [jealous==""] <- "n" > jealous=="" > CrossTable(group,jealous ,chisq=TRUE,resid=TRUE, missing.include=FALSE) > fisher.test(group,jealous) > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >____________________________________________________________________________________ No need to miss a message. Get email on-the-go