[R] xtable does not print out units of a variable
Shawn Way
SW@y @ending from meco@com
Thu Jul 19 00:53:34 CEST 2018
I have a dataframe that contains units using the units package. Unfortunately, I really need the units for reporting. I'm assuming that's because the data is in a class units and xtable doesn't know what to do with this.
The following is a MWE:
library(xtable)
library(units)
data <- data.frame(x=c(as_units(12,"ft")))
xtable(data)
% latex table generated in R 3.5.1 by xtable 1.8-2 package
% Wed Jul 18 17:31:44 2018
\begin{table}[ht]
\centering
\begin{tabular}{rr}
\hline
& x \\
\hline
1 & 12.00 \\
\hline
\end{tabular}
\end{table}
What I'm looking for is the line
1 & 12.00 \\
to be
1 & 12.00 $ft$\\
Can someone point me in the correct direction to make this happen? Since units are used extensively in engineering calculations, being able to handle this class would be extremely beneficial to engineers that are using R with knitr to generate engineering documents.
Shawn Way
More information about the R-help
mailing list