簡體   English   中英

遍歷 integer 64 數組會在 R 中打印不正確的值

[英]Iterating through an integer 64 array prints incorrect values in R

for循環和lapply本身不支持integer64嗎?

> x <- as.integer64(c("100000000000", "10000000000000"))
> x
integer64
[1] 100000000000   10000000000000
> for(y in x) {print(y)}
[1] 4.940656e-313
[1] 4.940656e-311
> tmp <- lapply(x, function(y) {print(y)})
[1] 4.940656e-313
[1] 4.940656e-311
> for(i in 1:length(x)) {print(x[i])}
integer64
[1] 100000000000
integer64
[1] 10000000000000
> as.list(x)
[[1]]
[1] 4.940656e-313

[[2]]
[1] 4.940656e-311
> as.list(as.integer64(x[1]))
[[1]]
[1] 4.940656e-313


您可以將其存儲在列表中並遍歷列表:

library(bit64)
z <- list(as.integer64("100000000000"), as.integer64("10000000000000"))

for(y in z) {print((y))}
#integer64
#[1] 100000000000
#integer64
#[1] 10000000000000

tmp <- lapply(z, function(y) {print(y)})
#integer64
#[1] 100000000000
#integer64
#[1] 10000000000000

或使用適用於lapplygmp

library(gmp)
x <- as.bigz(c("100000000000", "10000000000000"))

lapply(x, function(y) {print(y)})
#Big Integer ('bigz') :
#[1] 100000000000
#Big Integer ('bigz') :
#[1] 10000000000000

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM