[英]stargazer: error 'names' attribute must be the same length as vector
I want to use stargazer to export a table as .html:我想使用 stargazer 将表格导出为 .html:
iso <- c("AUT", "AUT", "BEG", "BEG", "BEG")
year <- c(2005, 2006, 2003, 2006, 2007)
tab1 <- table(iso, year)
stargazer(tab1, type = "html", summary = FALSE, out = "table1.html")
this gives me the following error:这给了我以下错误:
Error in names(x) <- value : 'names' attribute [4] must be the same length as the vector [3]
名称错误(x)<-值:“名称”属性 [4] 必须与向量 [3] 的长度相同
I don't understand what this means, is it because I have 4 distinct years?我不明白这是什么意思,是因为我有 4 个不同的年份吗? How can I get the code to work?
我怎样才能让代码工作?
stargazer
does not accept table
objects: stargazer
不接受table
对象:
one or more model objects (for regression analysis tables) or data frames/vectors/matrices (for summary statistics, or direct output of content).
一个或多个模型对象(用于回归分析表)或数据框/向量/矩阵(用于汇总统计,或直接输出内容)。 They can also be included as lists (or even lists within lists).
它们也可以作为列表(甚至列表中的列表)包含在内。
What you can do is use as.data.frame
for you input:您可以做的是使用
as.data.frame
为您输入:
library(stargazer)
stargazer(as.data.frame(tab1), type = "html", summary = FALSE, out = "table1.html")
Output:输出:
<table style="text-align:center"><tr><td colspan="4" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td>iso</td><td>year</td><td>Freq</td></tr>
<tr><td colspan="4" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">1</td><td>AUT</td><td>2003</td><td>0</td></tr>
<tr><td style="text-align:left">2</td><td>BEG</td><td>2003</td><td>1</td></tr>
<tr><td style="text-align:left">3</td><td>AUT</td><td>2005</td><td>1</td></tr>
<tr><td style="text-align:left">4</td><td>BEG</td><td>2005</td><td>0</td></tr>
<tr><td style="text-align:left">5</td><td>AUT</td><td>2006</td><td>1</td></tr>
<tr><td style="text-align:left">6</td><td>BEG</td><td>2006</td><td>1</td></tr>
<tr><td style="text-align:left">7</td><td>AUT</td><td>2007</td><td>0</td></tr>
<tr><td style="text-align:left">8</td><td>BEG</td><td>2007</td><td>1</td></tr>
<tr><td colspan="4" style="border-bottom: 1px solid black"></td></tr></table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.