1

I have written the following code to create a table in R. However, I cannot seem to get the format() digits command to work. I have a specific column "Population Mean" that I would like to separate the numbers in with digits ",".

'''

knitr::kable(mean_pop_1, "pipe", 
col.name=c("Country", "Population Mean"), 
align = c("l", "c"), 
caption = "Top 10 Countries Mean Population", format(","))

I receive this error:

Error in round(x[, j], digits[j]) : non-numeric argument to mathematical function '''

Data frame:

country       Population_mean
   <fct>                   <dbl>
 1 China              958160052.
 2 India              701130740.
 3 United States      228211232.
 4 Indonesia          148322833.
 5 Brazil             122312127.
 6 Japan              111758808 
 7 Pakistan            93683386.
 8 Bangladesh          90755395.
 9 Germany             77547043.
10 Nigeria             73708018.

Here the code for the example above:

df <- structure(list(Country = c("China", "India", "United States", 
                      "Indonesia", "Brazil", "Japan", "Pakistan", 
                       "Bangladesh", "Germany", "Nigeria"), 
                      Population_mean = c(958160052, 701130740, 
                       228211232, 148322833, 122312127, 111758808, 
                       93683386, 90755395, 77547043, 73708018)), 
                 row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
LucaCoding
  • 65
  • 12

1 Answers1

-1
knitr::kable(mean_pop_1, "pipe", format.args = list(big.mark = ","),
   col.name=c("Country", "Population Mean"), 
   align = c("l", "r"), caption = "Top 10 Countries Mean Population")
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213