简体   繁体   English

观星者:错误“名称”属性必须与矢量长度相同

[英]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.

相关问题 名称错误(x)&lt;-值:“名称”属性[8]的长度必须与向量[2]的长度相同 - Error in names(x) <- value : 'names' attribute [8] must be the same length as the vector [2] ggplot错误:“名称”属性[2]的长度必须与向量[1]相同 - ggplot error: 'names' attribute [2] must be the same length as the vector [1] R 错误:“名称”属性 [1] 的长度必须与向量 [0] 的长度相同 - R Error: 'names' attribute [1] must be the same length as the vector [0] plm 函数中的错误:&#39;names&#39; 属性 [343] 必须与向量 [0] 的长度相同 - Error in plm function: 'names' attribute [343] must be the same length as the vector [0] 视图错误:“名称”属性[1]的长度必须与矢量[0]的长度相同 - Error in View : 'names' attribute [1] must be the same length as the vector [0] ddply 错误的含义:'names' 属性 [9] 必须与向量 [1] 的长度相同 - meaning of ddply error: 'names' attribute [9] must be the same length as the vector [1] &#39;names&#39; 属性的长度必须与向量相同 - 'names' attribute must be the same length as vector &#39;names&#39; 属性 [1] 必须与向量 [0] 的长度相同 - 'names' attribute [1] must be the same length as the vector [0] &#39;names&#39; 属性的长度必须与向量相同 - 'names' attribute must be the same length as the vector 'names' 属性 [4000] 必须与向量 [5] 的长度相同 - 'names' attribute [4000] must be the same length as the vector [5]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM