我希望在R中创建一个摘要-星表,为变量“educ”和“exper”提供相应的观察数量N、均值、标准差、最小值和最大值。我使用下面的代码生成LaTeX表格。请注意保留HTML标记。
我得到了以下输出。正如您所看到的,表格出现了,但是它是空的。如果我使用标准的R数据(例如data("mtcars")),它可以工作。有人知道我的数据有什么问题吗?通常的R命令summary(wage2)可以完美地工作,但我无法在Latex中使用它。 谢谢!
数据长这样:
rm(list = ls())
wage2 <- read_csv("~/homework/wage2.txt")
library(stargazer)
stargazer(wage2[c("educ","exper")], type = "latex", digits=1,flip = TRUE)
我得到了以下输出。正如您所看到的,表格出现了,但是它是空的。如果我使用标准的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>
str(wage2)
和head(wage2)
,或者如果可能的话展示所有完整的数据,才能帮助你。 - Rafael Díaz