观星者摘要 table 为空
Stargazer summary table is empty
我想在 R 中做一个 summary-stargazer table,它给了我相应的观察次数 N,平均值,标准差,变量的最小值和最大值 "educ" 和"exper"。我使用以下代码在 Latex 中生成 table。
rm(list = ls())
wage2 <- read_csv("~/homework/wage2.txt")
library(stargazer)
stargazer(wage2[c("educ","exper")], type = "latex", digits=1,flip = TRUE)
我得到以下输出。如您所见,table 出现了,但它是空的。如果我使用标准 R 数据(例如 data("mtcars")),它就可以工作。任何人都有想法,我的数据可能有什么问题?通常的 R 命令 summary(wage2) 工作得很好,但我不能在 Latex 中使用它。
谢谢!
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University.
E-mail: hlavac at fas.harvard.edu
% Date and time: Mo, Mai 07, 2018 - 16:40:31
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lcc}
\[-1.8ex]\hline
\hline \[-1.8ex]
Statistic \
\hline \[-1.8ex]
N \
Mean \
St. Dev. \
Min \
Max \
\hline \[-1.8ex]
\end{tabular}
\end{table}
数据如下所示:
> str(wage2)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 935 obs. of 17 variables:
$ wage : int 769 808 825 650 562 1400 600 1081 1154 1000 ...
$ hours : int 40 50 40 40 40 40 40 40 45 40 ...
$ IQ : int 93 119 108 96 74 116 91 114 111 95 ...
$ KWW : int 35 41 46 32 27 43 24 50 37 44 ...
$ educ : int 12 18 14 12 11 16 10 18 15 12 ...
$ exper : int 11 11 11 13 14 14 13 8 13 16 ...
- attr(*, "spec")=List of 2
..$ cols :List of 17
.. ..$ wage : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ hours : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ IQ : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ KWW : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ educ : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ exper : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. .. ..- attr(*, "class")= chr "collector_double" "collector"
..$ default: list()
.. ..- attr(*, "class")= chr "collector_guess" "collector"
..- attr(*, "class")= chr "col_spec"
> head(wage2)
# A tibble: 6 x 17
wage hours IQ KWW educ exper tenure age married black south
urban sibs brthord
<int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
<int> <int> <int>
1 769 40 93 35 12 11 2 31 1 0 0
1 1 2
2 808 50 119 41 18 11 16 37 1 0 0
1 1 NA
3 825 40 108 46 14 11 9 33 1 0 0
1 1 2
4 650 40 96 32 12 13 7 32 1 0 0
1 4 3
5 562 40 74 27 11 14 5 34 1 0 0
1 10 6
6 1400 40 116 43 16 14 2 35 1 1 0
1 1 2
# ... with 3 more variables: meduc <int>, feduc <int>, lwage <dbl>
要生成摘要,stargazer 需要 data.frame 作为输入。由于您正在提供 tibble,stargazer 无法产生任何输出。
添加 as.data.frame() 应该可以解决问题 **.
stargazer(as.data.frame(wage2[c("educ","exper")]), type = "latex", digits=1,flip = TRUE)
** 免责声明:由于您没有提供可重现的示例,我创建了一个随机小标题来重现您的错误,并使用 as.data.frame() 再次尝试相同的代码,结果令人满意。但是我不能 "guarantee" 你的具体例子没有进一步的规范问题。
我想在 R 中做一个 summary-stargazer table,它给了我相应的观察次数 N,平均值,标准差,变量的最小值和最大值 "educ" 和"exper"。我使用以下代码在 Latex 中生成 table。
rm(list = ls())
wage2 <- read_csv("~/homework/wage2.txt")
library(stargazer)
stargazer(wage2[c("educ","exper")], type = "latex", digits=1,flip = TRUE)
我得到以下输出。如您所见,table 出现了,但它是空的。如果我使用标准 R 数据(例如 data("mtcars")),它就可以工作。任何人都有想法,我的数据可能有什么问题?通常的 R 命令 summary(wage2) 工作得很好,但我不能在 Latex 中使用它。 谢谢!
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University.
E-mail: hlavac at fas.harvard.edu
% Date and time: Mo, Mai 07, 2018 - 16:40:31
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lcc}
\[-1.8ex]\hline
\hline \[-1.8ex]
Statistic \
\hline \[-1.8ex]
N \
Mean \
St. Dev. \
Min \
Max \
\hline \[-1.8ex]
\end{tabular}
\end{table}
数据如下所示:
> str(wage2)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 935 obs. of 17 variables:
$ wage : int 769 808 825 650 562 1400 600 1081 1154 1000 ...
$ hours : int 40 50 40 40 40 40 40 40 45 40 ...
$ IQ : int 93 119 108 96 74 116 91 114 111 95 ...
$ KWW : int 35 41 46 32 27 43 24 50 37 44 ...
$ educ : int 12 18 14 12 11 16 10 18 15 12 ...
$ exper : int 11 11 11 13 14 14 13 8 13 16 ...
- attr(*, "spec")=List of 2
..$ cols :List of 17
.. ..$ wage : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ hours : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ IQ : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ KWW : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ educ : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ exper : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. .. ..- attr(*, "class")= chr "collector_double" "collector"
..$ default: list()
.. ..- attr(*, "class")= chr "collector_guess" "collector"
..- attr(*, "class")= chr "col_spec"
> head(wage2)
# A tibble: 6 x 17
wage hours IQ KWW educ exper tenure age married black south
urban sibs brthord
<int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
<int> <int> <int>
1 769 40 93 35 12 11 2 31 1 0 0
1 1 2
2 808 50 119 41 18 11 16 37 1 0 0
1 1 NA
3 825 40 108 46 14 11 9 33 1 0 0
1 1 2
4 650 40 96 32 12 13 7 32 1 0 0
1 4 3
5 562 40 74 27 11 14 5 34 1 0 0
1 10 6
6 1400 40 116 43 16 14 2 35 1 1 0
1 1 2
# ... with 3 more variables: meduc <int>, feduc <int>, lwage <dbl>
要生成摘要,stargazer 需要 data.frame 作为输入。由于您正在提供 tibble,stargazer 无法产生任何输出。
添加 as.data.frame() 应该可以解决问题 **.
stargazer(as.data.frame(wage2[c("educ","exper")]), type = "latex", digits=1,flip = TRUE)
** 免责声明:由于您没有提供可重现的示例,我创建了一个随机小标题来重现您的错误,并使用 as.data.frame() 再次尝试相同的代码,结果令人满意。但是我不能 "guarantee" 你的具体例子没有进一步的规范问题。