Hi, I have a string that I want to use in a variable call. How can I remove the quotes and/or the string properties of the string to use it in a variable call? Here's an example: library(lme) fm2 <- lme(distance ~ age, data = Orthodont, random = ~ 1) summary(fm2) I want to update the above regression to include new predictors according to what is in a string: predictors <- "age + Sex" update(fm2,fixed=distance ~ age + Sex) #this works update(fm2,fixed=distance ~ noquote(predictors)) #this doesn't work Any help would be greatly appreciated. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Remove-quotes-from-a-string-to-use-in-a-variable-call-tp4489370p4489370.html Sent from the R help mailing list archive at Nabble.com.
Rui Barradas
2012-Mar-20 19:36 UTC
[R] Remove quotes from a string to use in a variable call
Hello, dadrivr wrote> > Hi, > > I have a string that I want to use in a variable call. How can I remove > the quotes and/or the string properties of the string to use it in a > variable call? > > Here's an example: > > library(nlme) > fm2 <- lme(distance ~ age, data = Orthodont, random = ~ 1) > summary(fm2) > > I want to update the above regression to include new predictors according > to what is in a string: > > predictors <- "age + Sex" > update(fm2,fixed=distance ~ age + Sex) #this works > update(fm2,fixed=distance ~ noquote(predictors)) #this doesn't work > > Any help would be greatly appreciated. Thanks! >Try response <- "distance" predictors <- "age + Sex" fmla.text <- paste(response, predictors, sep="~") update(fm2,fixed=as.formula(fmla.text)) Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Remove-quotes-from-a-string-to-use-in-a-variable-call-tp4489370p4490120.html Sent from the R help mailing list archive at Nabble.com.