在R中创建一个漂亮的表,并使用format()函数创建数字



我已经编写了以下代码来在R中创建一个表。但是,我似乎无法使format()数字命令工作。我有一个特定的列CCD_ 2,我想用数字"&";。

''

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

我收到这个错误:

舍入错误(x[,j],digitals[j](:数学函数的非数字参数">

数据帧:

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.

这里是上面例子的代码:

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"))
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")

相关内容

最新更新