[R] Remove quotes from a string to use in a variable call

Rui Barradas rui1174 at sapo.pt
Tue Mar 20 20:36:34 CET 2012


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.



More information about the R-help mailing list