# How to use all variable in @formula like R language?

**URL:** https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031
**Category:** New to Julia
**Created:** [September 30, 2022, 10:20am UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031 "2022-09-30T10:20:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)
#### Post date: [September 30, 2022, 10:20am UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031/1 "2022-09-30T10:20:37Z")

</div>

```nohighlight
out <- glm(y ~ . , family=binomial(),data=turnout)

```

In R, above syntax works and i expected that’s similar to julia, but `.` is not a proper symbol in `GLM.jl` maybe.

```julia
julia> out = glm(@formula(y ~ .), train, Binomial())
ERROR: syntax: invalid identifier name "."

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 30, 2022, 10:40am UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031/2 "2022-09-30T10:40:22Z")

</div>

dup of

> [@Using all independent variables with @formula in a multiple linear model](https://discourse.julialang.org/t/using-all-independent-variables-with-formula-in-a-multiple-linear-model/43691/3):
>
> Edit2: Ok, is working now but I need to use your solution in the in the lm() directly, instead of being able to create a @formula variable. would be nice to be able to do a @formula variable, specially for cross validation and other that need to work with that. But for the time being, thank you again. Thanks, it was give me an error: LoadError: ArgumentError: non-call expression encountered: Term.(Symbol.(names(df[:, Not(:Y]))) but I solve it creating a variable with the sum of the independ…

---

<div class="post-metadata">

### Author: ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)
#### Post date: [September 30, 2022, 2:54pm UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031/3 "2022-09-30T14:54:22Z")

</div>

Thanks, but your solution is written at 2 years ago and i’ll very happy if there exists a better way. Is that still the best?

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [September 30, 2022, 2:57pm UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031/4 "2022-09-30T14:57:05Z")

</div>

Yes, still the best way.

Well, the way it’s written is awkward.

```julia

julia> term(:y) ~ sum(term.(names(df, Not(:y))))
FormulaTerm
Response:
  y(unknown)
Predictors:
  x1(unknown)
  x2(unknown)

```

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 30, 2022, 3:34pm UTC](https://discourse.julialang.org/t/how-to-use-all-variable-in-formula-like-r-language/88031/5 "2022-09-30T15:34:46Z")

</div>

Ha, I guess something did change in the intervening period and I should have known

> <https://github.com/JuliaStats/StatsModels.jl/pull/190>
>
> As discussed on Slack, this makes it easier to create \`Term\` objects from \`DataF…rame\` columns, as \`names(df)\` now returns strings.
