Reputation: 1
Regression <- top50 %>%
lm(Length.~Popularity) %>%
summary(Regression)
Error I am getting:
Error in as.data.frame.default(data) : cannot coerce class ‘"formula"’ to a data.frame
Upvotes: 0
Views: 90
Reputation: 388992
If you want to use pipes, try :
library(magrittr)
top50 %>% lm(Length.~Popularity, data = .) %>% summary
which is similar to
summary(lm(Length.~Popularity, data = top50))
Using reproducible example with mtcars
mtcars %>% lm(mpg~cyl, data = .) %>% summary
#Call:
#lm(formula = mpg ~ cyl, data = .)
#Residuals:
# Min 1Q Median 3Q Max
#-4.981 -2.119 0.222 1.072 7.519
#Coefficients:
# Estimate Std. Error t value Pr(>|t|)
#(Intercept) 37.885 2.074 18.27 < 2e-16 ***
#cyl -2.876 0.322 -8.92 6.1e-10 ***
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Residual standard error: 3.21 on 30 degrees of freedom
#Multiple R-squared: 0.726, Adjusted R-squared: 0.717
#F-statistic: 79.6 on 1 and 30 DF, p-value: 6.11e-10
Upvotes: 3