I have a table which I want to display that has a mix of percents, integers, and floating point values each in different rows of the table.
I would like to create formatted output in a R markup or Rnw file that nicely displays my table.
I can do it on a per column basis if I use xtable and the digits command.
I have investigated using the add.to.row functionality of print within a LaTeX output, however, I can not find a LaTeX tag that will apply a format to my numbers, they would all require braces to be around the individual numbers in order for the formatting to take effect, and I can't achieve that.
<<results=tex>>=
library(xtable)
### some random data
X<-data.frame();
for (i in 1:2) {
r<-sample(1:1000,4);
X<-rbind(X,r);
}
X<-rbind(X,(X[1,]/(X[1,]+X[2,])))
colnames(X)<-c("Cat A","Cat B","Cat C","Cat D")
rownames(X)<-c("Passed","Failed","Percent Passed")
###Atempts to format the rows
formTable<-xtable(X)
print(formTable)
###This works to format column
Y=t(X)
Y[,"Percent Passed"]=Y[,"Percent Passed"]*100;
formatedTab<-xtable(Y)
digits(formatedTab)<-c(0,0,0,2)
print(formatedTab)
@
If I could transpose the output of the second table I'd be happy...but that doesn't appear to work.
One particular reason I want this, is that I have very long row descriptions and short column descriptions so it's easier to have nice compact aligned columns.