質問

How can I add dollar symbol and round it to two digits in the table that's drawn by grid.draw of package gridExtra?

I am using round before I draw the table but I dont know how to round and add "$" together and draw the table. Any suggestion would be appreciated.

<code>enter image description here</code>

Here is my data df

           A          B
    aa 13.143733 0.09038618
    bb  1.459788 0.14159621
    cc  0.000000 0.00000000
    dd  4.884422 0.69697260
    ee 10.633865 2.92650123

grid.draw(tableGrob(df,show.csep=TRUE, show.rsep=TRUE, 
                          show.box=TRUE, separator="black", 
                          name="test",gp=gpar(fontsize=6, lwd=2)))
役に立ちましたか?

解決

Using plyr , you can use the colwise function to apply a function over many columns.

library(plyr)
dat <- numcolwise(round_any)(dat,0.01)
dat <- colwise(paste)(dat,'$')

enter image description here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top