[R] [External] Creating model formulas programmatically

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sat Mar 29 23:39:39 CET 2025


Thanks, Rich.

I thought of that, too, but it violates the spirit of my restraints (to
avoid character strings), which I unfortunately did not clearly articulate.
So my apologies for that failure. My concern is that with more complex
model formula, using as.formula, etc. to parse/convert character strings
can get a bit hairy. But in most cases, as here maybe, it may be perfectly
fine. So think of my post as mostly my attempt to learn some new tricks
rather than to solve a useful problem. I hope this is not unfair to the
list.

Cheers,
Bert





On Sat, Mar 29, 2025 at 3:12 PM Richard M. Heiberger <rmh using temple.edu> wrote:

> > somenames <- c("Heigh", "Ho", "Silver", "Away")
> > as.formula(paste("~(",paste(somenames, collapse="+"),")^2"))
> ~(Heigh + Ho + Silver + Away)^2
> >
>
> > On Mar 29, 2025, at 14:30, Bert Gunter <bgunter.4567 using gmail.com> wrote:
> >
> > somenames <- c("Heigh", "Ho", "Silver", "Away")
>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list