Stargazer 不在 R 工作室工作,我做错了什么?

问题描述 投票:0回答:1

我想使用 Stargazer 函数来描述我的描述性统计数据。我已经安装了 stargazer 包。

这是我的代码:

#Stargazer tables for word 
stargazer(as.matrix(psych::describe(data_corruption[c("innovation_firm", "corruption", "ownership_gov", "competition", "gender_tm", "size_firm", "age_firm", "RandD", "export", "corruption_constraint")])), type = "html", title="Descriptive statistics", digits = 2, out="Descriptive_statistics.doc")

这是我的错误:

Error in if (is.na(s)) { : the condition has length > 1

有人可以帮帮我吗?提前谢谢你。

请见上文。

谢谢。

r stargazer
1个回答
0
投票

我认为错误有时与变量的数量或变量/模型名称的长度有关。您的方法适用于最少的数据:

library(stargazer)

stargazer(as.matrix(psych::describe(mtcars)), type = "text", 
          title="Descriptive statistics", digits = 2)

Descriptive statistics
========================================================================================
     vars n   mean    sd   median trimmed  mad    min   max  range  skew  kurtosis  se  
----------------------------------------------------------------------------------------
mpg   1   32 20.09   6.03  19.20   19.70   5.41  10.40 33.90 23.50  0.61   -0.37   1.07 
cyl   2   32  6.19   1.79    6     6.23    2.97    4     8     4    -0.17  -1.76   0.32 
disp  3   32 230.72 123.94 196.30 222.52  140.48 71.10  472  400.90 0.38   -1.21   21.91
hp    4   32 146.69 68.56   123   141.19  77.10   52    335   283   0.73   -0.14   12.12
drat  5   32  3.60   0.53   3.70   3.58    0.70  2.76  4.93   2.17  0.27   -0.71   0.09 
wt    6   32  3.22   0.98   3.33   3.15    0.77  1.51  5.42   3.91  0.42   -0.02   0.17 
qsec  7   32 17.85   1.79  17.71   17.83   1.42  14.50 22.90  8.40  0.37    0.34   0.32 
vs    8   32  0.44   0.50    0     0.42     0      0     1     1    0.24   -2.00   0.09 
am    9   32  0.41   0.50    0     0.38     0      0     1     1    0.36   -1.92   0.09 
gear  10  32  3.69   0.74    4     3.62    1.48    3     5     2    0.53   -1.07   0.13 
carb  11  32  2.81   1.62    2     2.65    1.48    1     8     7    1.05    1.26   0.29 
----------------------------------------------------------------------------------------

也导出为.doc,试试这个,看看你是否仍然得到错误:

stargazer(as.matrix(psych::describe(mtcars)), type = "html", 
          title="Descriptive statistics", digits = 2, out="Descriptive_statistics.doc")

如果这个最小的命令对你有用,在你做 stargazer 之前尝试外包列选择:

df <- as.matrix(psych::describe(data_corruption[c("innovation_firm", "corruption", "ownership_gov", "competition", "gender_tm", "size_firm", "age_firm", "RandD", "export", "corruption_constraint")])

stargazer(df), type = "html", title="Descriptive statistics", digits = 2, out="Descriptive_statistics.doc")
© www.soinside.com 2019 - 2024. All rights reserved.