Display dollar sign in grid.draw

How can I add a dollar symbol and round it to two digits in the table drawn by the grid.draw

package gridExtra

?

I use round

before to draw the table, but I don't know how to round and add "$" together and draw the table. Any suggestion would be appreciated.

<code> enter image description here </code>
      <br>
        <script async src=
" data-src="/img/7ec563a6b09a4ea671e742bb57cb5a30.png" class=" lazyloaded" src="https://fooobar.com//img/7ec563a6b09a4ea671e742bb57cb5a30.png">

Here are my details 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)))

      

+3


source to share


1 answer


Using plyr

, you can use a function colwise

to apply a function on many columns.

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

      



enter image description here

+3


source







All Articles