Search code examples
rlatexpercentagestargazer

Make a percentage table with stargazer


I have data that looks like this, df1:

Product Relative_Value
Car     0.12651458
Plane   0.08888552
Tank    0.03546231
Bike    0.06711630
Train   0.06382191

Relative_Value is the percentage of the total sell of the product. I use stargazer(df1, summary=FALSE, rownames=TRUE) to get latex code to make a nice table of the data. But how do I get either R or TeXstudio to understand that Relative_Value should be formatted as percentage and not decimals?


Solution

  • You can use percent() from the scales package

    library(scales)
    
    df1 <- df1 %>%
        mutate(Relative_Value = percent(Relative_Value))
    

    Note that percent() changes the column type to character