点号后有“ 0”位的数字数据类型

问题描述 投票:0回答:1

[今天,我查看了pop程序包的wpp2019数据集,并注意到总体编号显示为带有“。”的数值。最后三位数字后的数字(例如10500为10.500)。

library(wpp2019)
data("pop")
pop$`2020`

要删除点,我通常会简单地将列变成字符列,然后使用例如stringr::str_replace(),但是一旦我对总体编号列应用了任何功能(打印除外),这些点就会消失。

[该数据集如何显示例如在打印data.frame时仍为10.500,即使R通常会删除数字值点后的0位数字?在上面的示例中删除点而不丢失0位的最佳方法是什么?

预期输出

 # instead of 
pop$`2020`[153]
#[1] 164.1
# this value should return 164100 because printing the data frame 
# shows 164.100
r numeric
1个回答
1
投票

wpp2019中的人口估算值以千为单位。因此,将其乘以1000即可得出估计的人数:

> pop$`2020`[153]*1000
[1] 164100

R根据digits中的print参数以及它正在打印的向量中的其他内容,有时但不显示小数部分。例如:

> print(1234567.890)
[1] 1234568 # max 7 digits printed by default

> print(c(1234567.890,0.011))
[1] 1234567.890       0.011 # but when printed alongside 0.011 all the digits shown.

这说明了为什么数据框总是显示所有数字,但是提取单个数字时却看不到所有数字。

© www.soinside.com 2019 - 2024. All rights reserved.