我有一个简单的问题,R中的tidy()
函数不起作用。我已经安装了tidyverse,并用library(tidyverse)
加载了它。然而,我收到以下错误消息:
Error in tidy(fit1b) : could not find function "tidy"
我在加载包时也会遇到以下冲突(只有"lfe"one_answers"tidyverse"包(,但我不确定它们是否导致了问题:
x tidyr::expand() masks Matrix::expand()
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
x tidyr::pack() masks Matrix::pack()
x tidyr::unpack() masks Matrix::unpack()
您需要的函数来自broom
,它不是tidyverse
的一部分。
参见:
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.2 ✔ purrr 0.3.4
✔ tibble 3.0.1 ✔ dplyr 1.0.0
✔ tidyr 1.1.0 ✔ stringr 1.4.0
✔ readr 1.3.1 ✔ forcats 0.5.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
tidy(lm(mpg ~ hp,data=mtcars))
Error in tidy(lm(mpg ~ hp, data = mtcars)) :
could not find function "tidy"
如果加载broom
:
library(broom)
tidy(lm(mpg ~ hp,data=mtcars))
# A tibble: 2 x 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 30.1 1.63 18.4 6.64e-18
2 hp -0.0682 0.0101 -6.74 1.79e- 7