[R] Issue with subset in glm
carlganz at ucla.edu
Tue Mar 21 16:50:12 CET 2017
I am experiencing odd behavior with the subset parameter for glm. It appears that the parameter uses non-standard evaluation, but only in some cases. Below is a reproducible example.
library(survey) # for example dataset
stype <- "E"
(a <- glm(api00~ell+meals+mobility, data = apistrat,
subset = apistrat$stype == stype))
(b <- glm(api00~ell+meals+mobility, data = apistrat,
subset = apistrat$stype == "E"))
# should be equal since stype = "E" but they aren't
# for some reason works as expected here
i = 4
(c <- glm(mpg ~ wt, data = mtcars, subset = mtcars$cyl==i))
(d <- glm(mpg ~ wt, data = mtcars, subset = mtcars$cyl==4))
I can't really explain what is happening so I would appreciate help.
More information about the R-help