Question

I am using R and LaTeX and the xtable package for tables. I am a little puzzled why my specified rownames aren't showing up in my tables. Here's an example:

\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<results=tex, fig=FALSE, echo=FALSE>>=
library(xtable)
table.matrix <- matrix(numeric(0), ncol = 5, nrow = 12)
colnames(table.matrix) <- c("$m_t$", "$p_t$", "$R^b_t$", "$R^m_t$", "$y^r_t$")
rownames(table.matrix) <- c("$m_{t-1}$", " ", "$p_{t-1}$", " ", "$R^b_{t-1}$", " ", "$R^m_{t-1}$", " ", "$y^r_t$", " ", "$c$", " ")

tex.table <- xtable(table.matrix)
align(tex.table) <- "c||ccccc"
print(tex.table, include.rownames = TRUE, hline.after = c(-1, 0, seq(0, nrow(table.matrix), by = 2)), sanitize.text.function = function(x){x})
@
\end{document}

It seems pretty straightforward to me. Essentially what I have is an estimation of a simple VAR model and in the rows I want the variables with a (t-1) subscript, and every second row should have the p-values (they're empty right now in the name vector). Any ideas?

EDIT: As pointed out by nograpes, the issue that some rownames are duplicates. Does anyone know how to circumvent this (without using the first column as a name column)? I just want the evenly numbered rows to be empty, alternatively some sort of indication they are p-values.

Was it helpful?

Solution

Try running just the R code, and you'll get a warning that tells you why the row names aren't showing up:

library(xtable)
table.matrix <- matrix(numeric(0), ncol = 5, nrow = 12)
colnames(table.matrix) <- c("$m_t$", "$p_t$", "$R^b_t$", "$R^m_t$", "$y^r_t$")
rownames(table.matrix) <- c("$m_{t-1}$", " ", "$p_{t-1}$", " ", "$R^b_{t-1}$", " ", "$R^m_{t-1}$", " ", "$y^r_t$", " ", "$c$", " ")

xtable(table.matrix)
# Warning message:
# In data.row.names(row.names, rowsi, i) :
#  some row.names duplicated: 4,6,8,10,12 --> row.names NOT used

So you can't have duplicated rownames in R. You could solve this by making a name "column" instead of using rownames.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top