xtab<-function(x, x2=NULL, caption=NULL, align=NULL, digits=NULL, rownames=NULL, colnames=NULL, force = TRUE){
m=nrow(x)
n=ncol(x)
if(!is.null(rownames(x))) rownames=rownames(x)
if(!is.null(colnames(x))) colnames=colnames(x)
cat('% latex table generated by xtab function\n')
cat('%',date(),'\n')
cat('\\begin{table}[ht]\n')
if(!is.null(caption))
cat('\\caption{',caption,'}\n',sep='')
cat('\\begin{center}\n')
if(is.null(align)) {
align = 'l'
for(i in 1:n) align = paste(align,'r',sep='')
}
if(nchar(align)==1){
atmp=align
for(i in 1:n) align = paste(align,atmp,sep='')
}
if(is.null(digits)) digits = rep(2,n)
if(length(digits)==1) digits = rep(digits,n+1)
cat('\\begin{tabular}{', align,'}\n', sep='')
cat('\\hline\n')
if(!is.null(colnames)){
for(j in 1:n)
cat('&',colnames[j],sep='')
cat('\\\\\n\\hline\n')
}
for(i in 1:m){
cat(rownames[i])
for(j in 1:n){
if(!is.character(x[i,j]))
cat('&',format(round(x[i,j],digits[j]),nsmall=digits[j]),sep='')
else cat('&',x[i,j],sep='')
if(!is.null(x2)) {
if(!is.character(x2[i,j]))
cat('(',format(round(x2[i,j],digits[j]),nsmall=digits[j]),')',sep='')
else
cat('(',x2[i,j],')',sep='')
}
}
cat('\\\\\n')
}
cat('\\hline\n')
cat('\\end{tabular}\n')
cat('\\end{center}\n')
cat('\\end{table}\n')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.