[R] How to pass a variable to a function which use variable name as a parameter

2015-05-26 Thread wong jane
There are functions which use variable names as parameters in some R packages. However, if the variable name is stored in another variable, how can I pass this variable to the function. Taking the "rms" package as an example: library(rms) n <- 1000 age <- rnorm(n, 50, 10) sex <- factor(sample(c('f

Re: [R] How to pass a variable to a function which use variable name as a parameter

2015-05-26 Thread John McKown
On Tue, May 26, 2015 at 5:14 AM, wong jane wrote: > There are functions which use variable names as parameters in some R > packages. However, if the variable name is stored in another variable, how > can I pass this variable to the function. Taking the "rms" package as an > example: > > ​​ > libr

Re: [R] How to pass a variable to a function which use variable name as a parameter

2015-05-26 Thread William Dunlap
One way to use variable names in functions like Predict() that do not evaluate their arguments in the standard way is to use do.call() along with as.name(). E.g., varName<-"age" do.call("Predict", list(fit, as.name(varName), np=4))}) gives the same result as Predict(fit, age, np=4) Bill D

Re: [R] How to pass a variable to a function which use variable name as a parameter

2015-05-26 Thread David Winsemius
On May 26, 2015, at 8:30 AM, William Dunlap wrote: > One way to use variable names in functions like Predict() that > do not evaluate their arguments in the standard way is to use > do.call() along with as.name(). E.g., > varName<-"age" > do.call("Predict", list(fit, as.name(varName), np=4))})