简体   繁体   English

as.character()和paste()是否受给出的数字值的大小限制?

[英]Are the as.character() and paste() limited by the size of the numeric vales they are given?

I'm running into some problems with the R function as.character() and paste() : they do not give back what they're being fed... 我在使用R函数as.character()paste()遇到了一些问题:它们不给与反馈。

as.character(1415584236544311111)
## [1] "1415584236544311040"

paste(1415584236544311111)
## [1] "1415584236544311040"

what could be the problem or a workaround to paste my number as a string? 将我的号码粘贴为字符串可能是什么问题或解决方法?

update 更新

I found that using the bit64 library allowed me to retain the extra digits I needed with the function as.integer64() . 我发现使用bit64库使我可以保留as.integer64()函数所需的额外数字。

Remember that numbers are stored in a fixed number of bytes based upon the hardware you are running on. 请记住,数字是根据运行的硬件以固定的字节数存储的。 Can you show that your very big integer is treated properly by normal arithmetic operations? 您能否证明您的大整数已通过常规算术运算正确处理? If not, you're probably trying to store a number to large to store in your R install's integer # of bytes. 如果不是这样,您可能正在尝试存储一个大数字以存储在R安装的整数字节数中。 The number you see is just what could fit. 您看到的数字正好适合。

You could try storing the number as a double which is technically less precise but can store larger numbers in scientific notation. 您可以尝试将数字存储为双精度数,这在技术上不太精确,但可以用科学计数法存储更大的数字。

EDIT 编辑

Consider the answers in long/bigint/decimal equivalent datatype in R which list solutions including arbitrary precision packages. 考虑Rlong / bigint / decimal等效数据类型的答案,其中列出了包括任意精度包的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM