It is simpler to format the df$value
with dollar format before using the xtable()
function. Using your example you have the following (which requires the scales
library):
library(xtable)
library(scales)
# create table data
year <- c("2010", "2011", "2012")
value <- c("5", "10", "15")
df<-data.frame(year, value)
df$value <- dollar(as.numeric(as.character(df$value)))
# print
print(xtable(df))
This produces the following LaTeX Code:
% latex table generated in R 2.12.2 by xtable 1.6-0 package
% Fri May 03 10:46:58 2013
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
\hline
& year & value \\
\hline
1 & 2010 & \$5.00 \\
2 & 2011 & \$10.00 \\
3 & 2012 & \$15.00 \\
\hline
\end{tabular}
\end{center}
\end{table}