1

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


4

1 回答 1

1

您可以将其存储在列表中并遍历列表:

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

或使用gmp适用于lapply

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

lapply(x, function(y) {print(y)})
#Big Integer ('bigz') :
#[1] 100000000000
#Big Integer ('bigz') :
#[1] 10000000000000
于 2021-05-10T09:49:56.750 回答