有没有办法将HTML tab_模型对象转换为R对象,如data.frame或tibble?

有没有办法将HTML tab_模型对象转换为R对象,如data.frame或tibble?,r,dataframe,transform,sjplot,R,Dataframe,Transform,Sjplot,有没有办法将HTML tab_模型对象转换为R对象,如data.frame或tibble 如果可以的话请告诉我。谢谢 以下是我用来创建tab_模型对象的代码: # Loads packages # ---- NOTE: making plots and diamonds dataset if(!require(ggplot2)){install.packages("ggplot2")} # ---- NOTE: run mixed effects models if

有没有办法将HTML tab_模型对象转换为R对象,如data.frame或tibble

如果可以的话请告诉我。谢谢



以下是我用来创建tab_模型对象的代码:




# Loads packages
# ---- NOTE: making plots and diamonds dataset
if(!require(ggplot2)){install.packages("ggplot2")}
# ---- NOTE: run mixed effects models
if(!require(lme4)){install.packages("lme4")}
# ---- NOTE: for data wrangling
if(!require(dplyr)){install.packages("dplyr")}
# ---- NOTE: for sjPlot command
if(!require(sjPlot)){install.packages("sjPlot")}

# dataset creation

## for dataset with top 300 rows
# ---- NOTE: selects only the top 300 rows of the dataset
diamonds_top300 <- data.frame(dplyr::top_n(ggplot2::diamonds, 300, y))
# ---- NOTE: gives dataset info
head(diamonds_top300)
str(diamonds_top300)
colnames(diamonds_top300)
nrow(diamonds_top300)

# model creation

## DV price for diamonds_top300, using poisson family
(
  mlm_top300_poisson_price <- 
    lme4::glmer(
      price ~ cut + color + carat + (1 | clarity) + (1 | depth),
      data = diamonds_top300,
      family = poisson()
    )
)

# creates tab_model object

## tab_model of mlm_top300_poisson_price
tab_model_mlm_top300_poisson_price <- 
  sjPlot::tab_model(mlm_top300_poisson_price)




#装载包裹
#----注:制作绘图和数据集
如果(!require(ggplot2)){install.packages(“ggplot2”)}
#----注意:运行混合效果模型
如果(!require(lme4)){install.packages(“lme4”)}
#----注:用于数据争用
如果(!require(dplyr)){install.packages(“dplyr”)}
#----注意:对于sjPlot命令
如果(!require(sjPlot)){install.packages(“sjPlot”)}
#数据集创建
##对于具有前300行的数据集
#----注意:仅选择数据集的前300行

钻石&u top300像这样的东西怎么样:

 library(XML)
 # first you parse the html, then you put it as table, taking the first
df <- data.frame(readHTMLTable(htmlParse(tab_model_mlm_top300_poisson_price))[1])
# first row as colnames
colnames(df) <- df[1,]
# remove the fake first row
df <- df[-1,]

 df
                     Predictors Incidence Rate Ratios                CI      p
2                   (Intercept)               6754.63 5410.16 – 8433.23 <0.001
3                  cut [linear]                  1.08       1.07 – 1.09 <0.001
4               cut [quadratic]                  0.95       0.94 – 0.96 <0.001
5                   cut [cubic]                  1.04       1.04 – 1.05 <0.001
6              cut [4th degree]                  1.04       1.04 – 1.05 <0.001
7                color [linear]                  0.94       0.93 – 0.95 <0.001
8             color [quadratic]                  0.97       0.97 – 0.98 <0.001
9                 color [cubic]                  0.92       0.91 – 0.92 <0.001
10           color [4th degree]                  1.12       1.11 – 1.12 <0.001
11           color [5th degree]                  0.88       0.87 – 0.88 <0.001
12           color [6th degree]                  1.05       1.04 – 1.05 <0.001
13                        carat                  1.43       1.42 – 1.44 <0.001
14               Random Effects                  <NA>              <NA>   <NA>
15                           s2                  0.00              <NA>   <NA>
16                     t00depth                  0.01              <NA>   <NA>
17                   t00clarity                  0.08              <NA>   <NA>
18                          ICC                  1.00              <NA>   <NA>
19                    N clarity                     6              <NA>   <NA>
20                      N depth                    83              <NA>   <NA>
21                 Observations                   305              <NA>   <NA>
22 Marginal R2 / Conditional R2         0.183 / 0.999              <NA>   <NA>
库(XML)
#首先解析html,然后将其作为表,取第一个
df