1

When generating terms from a formula, R seems to sometimes change the order of the variables:

> terms(~ strata:dayname:hour_local + treat_assign:dayname:hour_local) |> labels()

[1] "strata:dayname:hour_local"       "dayname:hour_local:treat_assign"

Is there any way to either prevent this reordering from happening, or to map between elements in the formula and the terms?

RoyalTS
  • 9,545
  • 12
  • 60
  • 101

1 Answers1

1

We could use reformulate:

R will order the terms alphabetically by default. We could control the order of the terms manually with reformulate().

reformulate(c("strata:dayname:hour_local", "treat_assign:dayname:hour_local"), response = ".")
~ strata:dayname:hour_local + treat_assign:dayname:hour_local
TarJae
  • 72,363
  • 6
  • 19
  • 66