[R] Writing a tabel in LaTeX-format
Helgi Tomasson
helgito at hi.is
Fri Sep 8 13:35:35 CEST 2000
Here is another attempt less sophisticated than the one from Martina
Helgi
Martina Erdbrügge wrote:
> Hi there,
>
> here's another attempt to write a nice function that converts a matrix
> into Latex-code. Maybe you want to try it (it's an english version).
>
> Martina
>
> "BXC (Bendix Carstensen)" wrote:
> >
> > I have a vague recollection of seeing a R-function
> > that will output a table or matix in a format suitable
> > for the tabular enviroment in LaTeX.
> >
> > But I cannot find it. Any hints?
>
> ------------------------------------------------------------------------
> Name: latex_table.R
> latex_table.R Type: application/x-unknown-content-type-R_auto_file
> Encoding: base64
--
Helgi Tomasson FAX: 354-552-6806
University of Iceland PHONE:354-525-4571
Faculty of Economics and Business Administration email:helgito at rhi.hi.is
Oddi v/ Sturlugotu
IS-101 Reykjavik
ICELAND
-------------- next part --------------
#
# sparesly commented conversion of matrix to tex
# input, table and required precision
# output, vector of strings that can be writte to a file
#
#
rmatrix2textable <- function(dreif,pres)
{
radir <- nrow(dreif)
dreiftafla <- vector('character',radir+2)
dalkar <- ncol(dreif)
rstafir <- c("r","r","r","r",
"r","r",
"r","r",
"r","r",
"r","r",
"r","r")
fyrirsogn <- c("\\begin{tabular}{",rstafir[1:dalkar],"}")
dreiftafla[1] <- paste(fyrirsogn,sep="",collapse="")
jxx <- 1
while (jxx < radir+1)
{
ixx <- 1
lina <- vector('character',2*dalkar)
while (ixx < dalkar+1)
{
lina[2*ixx-1] <- formatC(dreif[jxx,ixx],digits=pres,format='f')
lina[2*ixx] <- " & "
ixx <- ixx+1
}
lina[2*dalkar] <- " \\\\"
dreiftafla[jxx+1] <- paste(lina,sep="",collapse="")
jxx <- jxx+1
}
dreiftafla[radir+2] <- "\\end{tabular}"
return(dreiftafla)
}
#
#
#
More information about the R-help
mailing list