Instead of using a loop, consider using the existing print.xtable function in conjunction with an insert.
hdashlines: Consider using print.xtable options. For example, there is an hline.after parameter that controls the horizontal lines between the lines of the table.
vspace: This is possibly simpler with paste .
For example:
library(xtable) df <- data.frame(name=rep(letters[1:3],each=24),salary=runif(24*3,100,200)) lst <- tapply(df$salary,df$name,matrix,nrow=4,byrow=T) xlst <- lapply(lst,function(x)print(xtable(x), hline.after=1:nrow(x))) xlst <- lapply(xlst, paste, "\\vspace{2em}") xlst
[1] "% latex table generated in R 2.13.1 using the xxtable 1.5-6 package \ n% Tue Aug 23 13:36:41 2011 \ n \ BEGIN {table} [XT] \ n \ {start center } \ n \ {start tabular} {RRRRRRR} \ n and 1 and 2 and 3 and 4 and 5 and 6 \\\ n 1 and 158.66 and 115.81 and 106.70 and 128.78 and 157.43 and 191.01 \\\ n \ hline \ n2 and 159.09 and 172.31 and 153.93 & 127.91 and 106.93 and 147.95 \\\ n \ hline \ n3 and 135.65 and 139 , 45 & 192.90 and 108.78 and 186.52 and 164.10 \\\ n \ hline \ n4 and 190.10 & 154.39 and 124.91 and 199.24 and 161.99 and 167.61 \\\ n
\ hline \ n \ end {tabular} \ n \ end {center} \ n \ end {table} \ n \ vspace {2em} "
See ?print.xtable more details. If hline.after not flexible enough for your purposes, see add.to.row , where you can specify both the position and the exact type of element to add.
Andrie
source share