Reputation: 729
Sales is a variable in the dataset train. Summary() finds it, but not glm(). What's going on?
Any help is appreciated.
> summary(train$Sales)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0 3727 5744 5774 7856 41550
> summary(ross_glm <- glm(Sales ~ Customers,family=Gamma,data = train[Sales>0]))
Error in `[.data.frame`(train, Sales > 0) : object 'Sales' not found
P.S. I've tried referencing using train$Sales and also attaching the train dataset, but they don't resolve the problem.
Upvotes: 0
Views: 3406
Reputation:
Edit: Ben Bolker's comment provides a cleaner way to subset inside the function glm
.
There is problem in the way you subset your data.frame. It should be train[train$Sales>0,]
(don't forget the ,
after the filter).
set.seed(42)
train <- data.frame(Sales = rnorm(100), Other = rnorm(100))
train[Sales>0]
Error in
[.data.frame
(train, Sales > 0) : object 'Sales' not found
head(train[train$Sales>0,])
# Sales Other
# 1 1.3709584 1.2009654
# 3 0.3631284 -1.0032086
# 4 0.6328626 1.8484819
# 5 0.4042683 -0.6667734
# 7 1.5115220 -0.4222559
# 9 2.0184237 0.1881930
Upvotes: 4