[R] latex.table for table with character and numeric columns
Gerrit Draisma
g.draisma at erasmusmc.nl
Mon Dec 7 16:59:02 CET 2009
Ha Charlie,
It helped.
It is just what i was looking for.
Gerrit.
> 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
More information about the R-help
mailing list