[R] latex.table for table with character and numeric columns

Sharpie chuck at sharpsteen.net
Fri Dec 4 20:43:14 CET 2009



Gerrit Draisma wrote:
> 
> Hallo,
> I have a dataset with one or two columns with character data
> and the rest with numeric data.
> Using latex.table from the quantreg package produced a table,
> but I cannot set the decimals.
> For instance:
> ---
>  > x<-data.frame(Name=c("Jan","Piet","Jan"), V=c(1,2.991,3))
>  > latex.table(as.matrix(x),file="x",caption="x")
>  > latex.table(as.matrix(x),file="x",caption="x",dec=2)
> Error in round(x, dec) : Non-numeric argument to mathematical function
>  >
> ---
> Am I not using the right command, or is there a way around?
> Thanks,
> Gerrit.
> 


Hi Gerrit,

I haven't used latex.table from quantreg so I can't comment on this
approach. However, I would recommend using the xtable package to format your
data.frame into LaTeX:

  require( xtable )

  x<-data.frame(Name=c("Jan","Piet","Jan"), V=c(1,2.991,3))

  # Create a table object from the data.frame
  latexTable <- xtable( x )

  # Set the number of digits in each column. Your example has two columns,
  # but we must specify three digits since the rownames count as a column.
  digits( latexTable ) <- c( 0, 0, 2 )

  # Print the table object in order to produce the LaTeX code.
  print( latexTable )

You should also read the help page for print.xtable() as it discusses many
options that can affect the final LaTeX output.

Hope this helps!

-Charlie
-- 
View this message in context: http://n4.nabble.com/latex-table-for-table-with-character-and-numeric-columns-tp948559p948812.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list