[R] How to pass a string as an argument to a function?

Gang Chen gangchen at mail.nih.gov
Wed Sep 19 19:34:51 CEST 2007


I want to pass a predefined string ww ("fa*fb+fc") to function lme so  
that I can run

 > lme(y ~  fa*fb+fc, random = ~1|subj, model)

I've tried something like

 > lme(y ~  paste(ww), random = ~1|subj, model)

and

 > lme(y ~  sprintf(ww), random = ~1|subj, model)

but both give me the following error:

Error in model.frame(formula, rownames, variables, varnames, extras,  
extranames,  :
         variable lengths differ (found for 'ww')

There must be a simple way to do this. Any help?

Thanks,
Gang



More information about the R-help mailing list