A simple definition of the first three coefficients is quite simple:
reg.table$coefficients <- reg.table$coefficients[,,1:3,,drop=FALSE] toLatex(reg.table)
The βbonusβ question (i.e. adding the 4th line created manually with the description of the βgroupβ) requires a bit more work:
## Select the first three coeffients + one to be modified reg.table$coefficients <- reg.table$coefficients[,,1:4,,drop=FALSE] ## Make a copy of all the coefficients, and in the copy, modify the 4th j <- reg.table$coefficients j[,,4,] <- c("yes", "", "yes", "", "no", "") dimnames(j)[[3]][4] <- "group" ## Put the modified coefficients back into `reg.table` reg.table$coefficients <- j
et voila
toLatex(reg.table) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Calls: % Model 1: lm(formula = y ~ x + z + factor(group), data = df) % Model 2: lm(formula = y ~ x + factor(group), data = df) % Model 3: lm(formula = y ~ x + z, data = df) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{tabular}{lcD{.}{.}{7}cD{.}{.}{7}cD{.}{.}{7}} \toprule &&\multicolumn{1}{c}{Model 1} && \multicolumn{1}{c}{Model 2} && \multicolumn{1}{c}{Model 3}\\ \midrule (Intercept) & & 8.830^{***} && 9.846^{**} && 10.342^{***} \\ & & (0.626) && (3.272) && (0.442) \\ x & & 2.047^{***} && 1.765 && 1.937^{***} \\ & & (0.244) && (1.276) && (0.319) \\ z & & 5.138^{***} && && 4.847^{***} \\ & & (0.267) && && (0.372) \\ group & & yes && yes && no \\ & & && && \\ \midrule sigma & & 1.204 && 6.310 && 1.812 \\ R-squared & & 0.975 && 0.270 && 0.927 \\ F & & 85.576 && 1.033 && 107.717 \\ p & & 0.000 && 0.436 && 0.000 \\ N & & 20 && 20 && 20 \\ \bottomrule \end{tabular}
Edit:
Here I like the version even better. It describes the first OP comment below and uses abind() (e.g. rbind() for arrays) to add group information to an array that I think is cleaner:
library(abind) j <- reg.table$coefficients groupFac <- array(c("yes", "", "yes", "", "no", ""), dim=c(2,1,3)) nonGroupFacs <- which(!grepl("group", dimnames(j)[[3]])) j <- j[,,nonGroupFacs,,drop=FALSE] j <- abind(j, groupFac, along=3) dimnames(j)[[3]][length(nonGroupFacs)+1] <- "group" reg.table$coefficients <- j toLatex(reg.table)