观星者摘要表为空。

5
我希望在R中创建一个摘要-星表,为变量“educ”和“exper”提供相应的观察数量N、均值、标准差、最小值和最大值。我使用下面的代码生成LaTeX表格。请注意保留HTML标记。
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
谢谢您的提示。我编辑了问题并添加了数据。 - MARIUS
1个回答

9
为了生成摘要,stargazer需要一个data.frame作为输入。由于你提供了一个tibble,stargazer无法生成任何输出。
添加as.data.frame()可以解决这个问题 **。
stargazer(as.data.frame(wage2[c("educ","exper")]), type = "latex", digits=1,flip = TRUE)

**声明:由于您没有提供可重现的示例,我创建了一个随机的tibble来复制您的错误,并尝试使用as.data.frame()再次运行相同的代码,得到了令人满意的结果。但是我不能“保证”您特定的示例不会受到进一步的规范问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接