[英]Iterating through an integer 64 array prints incorrect values in R
Do for
loop and lapply
not inherently support integer64
? 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
You can store it in a list and iterate over the list:您可以将其存储在列表中并遍历列表:
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
or use gmp
which works for lapply
:或使用适用于
lapply
的gmp
:
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.