0

I want to report correlation tables in a latex report and I'm using 'stargazer' to transform my R objects into tex-code. The correlational data is currently stored in a data frame.

I would like to print rownames and possibly add an annotation under the table. I couldn't find a 'print rownames'-argument and the 'notes'-argument doesn't seem to work.

Any Ideas?

## create object
x           <- matrix(1:4, 2, byrow = TRUE)
dimnames(x) <- list(c("A", "B"), c("A", "B"))
x           <- data.frame(x)

## create Tex-Code
stargazer(x, summary = FALSE, title = "2x2 Matrix",
          notes = "This is a two by two Matrix")
4

3 回答 3

1

从5.0版本开始,stargazer可以直接输出矩阵/向量的内容。以下代码应该为您的问题提供简单直观的解决方案:

## create object
x           <- matrix(1:4, 2, byrow = TRUE)
dimnames(x) <- list(c("A", "B"), c("A", "B"))

## create Tex-Code
stargazer(x, title = "2x2 Matrix",
          notes = "This is a two by two Matrix")
于 2014-03-06T19:09:13.510 回答
0

这是一个降价解决方案,可以使用例如Pandoc转换为 LaTeX :

> require(pander)
> pander(x, caption = 'Annotation')

---------------
&nbsp;   A   B 
------- --- ---
 **A**   1   2 

 **B**   3   4 
---------------

Table: Annotation
于 2013-10-12T20:26:13.253 回答
0

要获取“rownames”,请尝试以下 hackish 解决方案:

## create object
x           <- matrix(1:4, 2, byrow = TRUE)
x           <- data.frame(x)
x           <- cbind(c("A","B"),x)
colnames(x) <- c("","A", "B")

## create Tex-Code
stargazer(x, summary = FALSE, title = "2x2 Matrix",
          notes = "This is a two by two Matrix", type="text")

目前(v. 4.5.1),“stargazer”最适合使用回归表和数据框。但是,您的问题表明用户可能对更好地支持矩阵感兴趣。预计在未来的版本中(接下来的几个月)。

至于注释,这些目前仅适用于回归表。但是,它们将在下一版本中用于汇总统计信息和数据框表。如果您愿意编辑源代码,则可以通过替换以下行来获得与未来实现非常接近(尽管不是很完美)的东西:

.format.s.stat.parts <<- c("-!","stat names","-!","statistics1","-!")

经过:

.format.s.stat.parts <<- c("-!","stat names","-!","statistics1","-!","notes")
于 2013-10-13T20:21:14.287 回答