Re: [R] Creating model formulas programmatically

2025-03-31 Thread Duncan Murdoch
On 2025-03-30 11:41 a.m., Bert Gunter wrote: Gabor, Duncan, et. al. 1. Thank you for your great comments and solutions. This is what I was hoping for! 2. Duncan: I completely agree with your criticisms. In fact, I realized the for() loop only needed the <- assignment, but your comment is import

Re: [R] Creating model formulas programmatically

2025-03-30 Thread Gabor Grothendieck
Another solution. reformulate + substitute + as.formula: substitute(~ (.)^2, list(. = reformulate(somenames)[[2]])) |> as.formula() On Sat, Mar 29, 2025 at 5:31 PM Bert Gunter wrote: > > Note: I am almost certain that this has been asked and answered here > before, so my apologies for the redun

Re: [R] Creating model formulas programmatically

2025-03-30 Thread Bert Gunter
Gabor, Duncan, et. al. 1. Thank you for your great comments and solutions. This is what I was hoping for! 2. Duncan: I completely agree with your criticisms. In fact, I realized the for() loop only needed the <- assignment, but your comment is important to note. However, I didn't like the for() l

Re: [R] Creating model formulas programmatically

2025-03-30 Thread Gabor Grothendieck
reformulate + update: somenames |> reformulate() |> update(~ (.)^2) On Sat, Mar 29, 2025 at 5:31 PM Bert Gunter wrote: > > Note: I am almost certain that this has been asked and answered here > before, so my apologies for the redundant query. > > I also know that there are several packages that

Re: [R] Creating model formulas programmatically

2025-03-29 Thread Duncan Murdoch
Your approach seems reasonable to me, though I wouldn't do it that way. The way I work this sort of thing out is to get R to do a simple example, then see what it did, and duplicate that. For example, f <- ~ (Heigh + Ho + Silver + Away)^2 Then look at as.list(f), as.list(f[[2]]), as.list(

[R] Creating model formulas programmatically

2025-03-29 Thread Bert Gunter
Note: I am almost certain that this has been asked and answered here before, so my apologies for the redundant query. I also know that there are several packages that will do this, but I wish to do it using base R functions only (see below). The query: Suppose I have a character vector of names l