as.data.frame.default(data)出错:无法将类“”公式“”强制转换为data.frame

时间:2018-04-11 15:15:50

标签: r dataframe error-handling pipe

我不太清楚为什么我会收到此错误或含义。我的数据框称为“数据”。

  library(dplyr)
  data %>%
  filter(Info==1, Male==1) %>%
  lm(CFL_Purchased ~ Male)  %>% 
  summary()

谢谢!

1 个答案:

答案 0 :(得分:0)

这对我有用:

library(dplyr)

dat <- data.frame(x = rnorm(10000, 4, 3),
                  y = rnorm(10000, 2, 2))

dat %>%
  lm(y ~ x,.) %>%
  summary()

Call:
lm(formula = y ~ x, data = .)

Residuals:
    Min      1Q  Median      3Q     Max 
-7.5620 -1.3678 -0.0307  1.3625  8.0371 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 1.952941   0.033064  59.065   <2e-16 ***
x           0.008841   0.006617   1.336    0.182    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.001 on 9998 degrees of freedom
Multiple R-squared:  0.0001785, Adjusted R-squared:  7.852e-05 
F-statistic: 1.785 on 1 and 9998 DF,  p-value: 0.1815