Dear expeRts, I am currently struggling with the problem of finding cut points for a set of stimulus variables. I would like to obtain cut points iteratively for each variable by re-applying a dichotomised variable in the model and then recalculate it. I planned to have fixed names for the dichotomised variables so I could use the same syntax for every recalculation of the whole model. I furthermore want to reiterate the process until no cut point changes any more. My problem is in accomplishing this syntactically. How can I pass a variable name to a function without getting lost in "as.symbol" and "eval" and "parse" mayhem? I am feeling I am thinking too much in macro expansion ? la SAS when trying to tackle this.
Macro stuff ? la SAS is something that should be avoided whenever possible - it's messy, limited, and limiting. (I've done it ocasionally and it works, but I think it's best not to go there.) Read the documentation on lists (in particular named lists), and keep everything in one or more lists. For example: lst <- list() for (v in c("var1","var2","var3")) lst[[v]] <- runif(sample(c(50,100),1)) for (v in c("var1","var2","var3")) print(sd(lst[[v]]))> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Johannes H?sing > Sent: Tuesday, May 23, 2006 12:26 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Manipulating code? > > Dear expeRts, > I am currently struggling with the problem of finding > cut points for a set of stimulus variables. I would like > to obtain cut points iteratively for each variable by > re-applying a dichotomised variable in the model and then > recalculate it. I planned to have fixed names for the > dichotomised variables so I could use the same syntax > for every recalculation of the whole model. I furthermore > want to reiterate the process until no cut point changes > any more. > > My problem is in accomplishing this syntactically. How can > I pass a variable name to a function without getting lost > in "as.symbol" and "eval" and "parse" mayhem? I am feeling > I am thinking too much in macro expansion ? la SAS when > trying to tackle this. > > ______________________________________________ > 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 >
Johannes H?sing <johannes at huesing.name> writes:> Dear expeRts, > I am currently struggling with the problem of finding > cut points for a set of stimulus variables. I would like > to obtain cut points iteratively for each variable by > re-applying a dichotomised variable in the model and then > recalculate it. I planned to have fixed names for the > dichotomised variables so I could use the same syntax > for every recalculation of the whole model. I furthermore > want to reiterate the process until no cut point changes > any more. > > My problem is in accomplishing this syntactically. How can > I pass a variable name to a function without getting lost > in "as.symbol" and "eval" and "parse" mayhem? I am feeling > I am thinking too much in macro expansion ? la SAS when > trying to tackle this.I think a simple example of what you are trying to do might be needed. But take a look at the help pages for assign() and get(). These functions make it easy to go from string containing name of variable to the actual variable, etc. + seth
Its not entirely clear to me what you want to do but these will do the indicated regression on the subset of the data for which Species is "setosa" and then do it again but for the subset for which Species is "virginica": lm(Sepal.Length ~ Sepal.Width, iris, subset = Species == "setosa") lm(Sepal.Length ~ Sepal.Width, iris, subset = Species == "virginica") Does that answer your question? On 5/23/06, Johannes H?sing <johannes at huesing.name> wrote:> Dear expeRts, > I am currently struggling with the problem of finding > cut points for a set of stimulus variables. I would like > to obtain cut points iteratively for each variable by > re-applying a dichotomised variable in the model and then > recalculate it. I planned to have fixed names for the > dichotomised variables so I could use the same syntax > for every recalculation of the whole model. I furthermore > want to reiterate the process until no cut point changes > any more. > > My problem is in accomplishing this syntactically. How can > I pass a variable name to a function without getting lost > in "as.symbol" and "eval" and "parse" mayhem? I am feeling > I am thinking too much in macro expansion ? la SAS when > trying to tackle this. > > ______________________________________________ > 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 >