Created
August 1, 2017 11:36
-
-
Save lorenzwalthert/e16048efdd2e02e0e0eee59f6966879a to your computer and use it in GitHub Desktop.
formula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
string_formula <- paste0(names(mtcars)[1], " ~", paste0(names(mtcars)[-1], collapse = "+")) | |
lm(as.formula(string_formula), data = mtcars) | |
#> | |
#> Call: | |
#> lm(formula = as.formula(string_formula), data = mtcars) | |
#> | |
#> Coefficients: | |
#> (Intercept) cyl disp hp drat | |
#> 12.30337 -0.11144 0.01334 -0.02148 0.78711 | |
#> wt qsec vs am gear | |
#> -3.71530 0.82104 0.31776 2.52023 0.65541 | |
#> carb | |
#> -0.19942 | |
mtcars$blablabla <- 3 | |
lm(as.formula(string_formula), data = mtcars) | |
#> | |
#> Call: | |
#> lm(formula = as.formula(string_formula), data = mtcars) | |
#> | |
#> Coefficients: | |
#> (Intercept) cyl disp hp drat | |
#> 12.30337 -0.11144 0.01334 -0.02148 0.78711 | |
#> wt qsec vs am gear | |
#> -3.71530 0.82104 0.31776 2.52023 0.65541 | |
#> carb | |
#> -0.19942 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment