Created
August 24, 2017 01:06
-
-
Save DavisVaughan/7ff5125d037397a8f2cd7beb07b0e205 to your computer and use it in GitHub Desktop.
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
library(rlang) | |
library(tibble, warn.conflicts = FALSE) | |
# A formula for the cars dataset | |
f <- as.formula("speed ~ dist") | |
f | |
#> speed ~ dist | |
#> <environment: 0x7f8399800d80> | |
# X | |
X <- model.matrix(f, data = cars) | |
head(X) | |
#> (Intercept) dist | |
#> 1 1 2 | |
#> 2 1 10 | |
#> 3 1 4 | |
#> 4 1 22 | |
#> 5 1 16 | |
#> 6 1 10 | |
# Y - but as a vector, not as a data.frame with a column name | |
Y <- model.response(model.frame(f, data = cars)) | |
head(Y) | |
#> 1 2 3 4 5 6 | |
#> 4 4 7 7 8 9 | |
# When you take tidy eval too far | |
Y <- tibble(!! f_lhs(f) := Y) | |
head(Y) | |
#> # A tibble: 6 x 1 | |
#> speed | |
#> <dbl> | |
#> 1 4 | |
#> 2 4 | |
#> 3 7 | |
#> 4 7 | |
#> 5 8 | |
#> 6 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment