Tidyverse 的 tidy() 函数在 R 中不起作用

can*_*tml 3 r broom tidyverse

我有一个简单的问题,tidy()R 中的函数不起作用。我已经安装了 tidyverse 并加载了library(tidyverse). 但是我收到以下错误消息:

Error in tidy(fit1b) : could not find function "tidy"
Run Code Online (Sandbox Code Playgroud)

加载软件包时(仅“lfe”和“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()
Run Code Online (Sandbox Code Playgroud)

Stu*_*olf 8

您需要的功能来自broom,但它不是 的一部分tidyverse

\n

看:

\n
library(tidyverse)\n\xe2\x94\x80\xe2\x94\x80 Attaching packages \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 tidyverse 1.3.0 \xe2\x94\x80\xe2\x94\x80\n\xe2\x9c\x94 ggplot2 3.3.2     \xe2\x9c\x94 purrr   0.3.4\n\xe2\x9c\x94 tibble  3.0.1     \xe2\x9c\x94 dplyr   1.0.0\n\xe2\x9c\x94 tidyr   1.1.0     \xe2\x9c\x94 stringr 1.4.0\n\xe2\x9c\x94 readr   1.3.1     \xe2\x9c\x94 forcats 0.5.0\n\xe2\x94\x80\xe2\x94\x80 Conflicts \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 tidyverse_conflicts() \xe2\x94\x80\xe2\x94\x80\n\xe2\x9c\x96 dplyr::filter() masks stats::filter()\n\xe2\x9c\x96 dplyr::lag()    masks stats::lag()\n\ntidy(lm(mpg ~ hp,data=mtcars))\nError in tidy(lm(mpg ~ hp, data = mtcars)) : \n  could not find function "tidy"\n
Run Code Online (Sandbox Code Playgroud)\n

如果您加载broom

\n
library(broom)\ntidy(lm(mpg ~ hp,data=mtcars))\n# A tibble: 2 x 5\n  term        estimate std.error statistic  p.value\n  <chr>          <dbl>     <dbl>     <dbl>    <dbl>\n1 (Intercept)  30.1       1.63       18.4  6.64e-18\n2 hp           -0.0682    0.0101     -6.74 1.79e- 7\n
Run Code Online (Sandbox Code Playgroud)\n