"5" as.integer-6ren">
gpt4 book ai didi

r - as.integer(max(factorize(15))) 的评估

转载 作者:行者123 更新时间:2023-12-03 23:10:30 25 4
gpt4 key购买 nike

这对我来说似乎很奇怪,我想要一个解释。一世

library(gmp)
factorize(15) # => "3" "5"
max(factorize(15)) # => "5"
as.integer("5") # => 5
as.integer(max(factorize(15))) # => 1 0 0 0 1 0 0 0 1 0 0 0 5 0 0 0

我可以做我想做的事:
max(as.numeric(factorize(15))) # => [1]5

但是让我震惊的是,我不能依赖于在所谓的类似方案的语言中的函数内部嵌套函数。我错过了什么吗?

最佳答案

嗯,答案就在 factorize(15) 的表示中:

> dput(factorize(15))
structure(c(02, 00, 00, 00, 01, 00, 00, 00, 01, 00, 00, 00, 03,
00, 00, 00, 01, 00, 00, 00, 01, 00, 00, 00, 05, 00, 00, 00), class = "bigz")


> dput(max(factorize(15)))
structure(c(01, 00, 00, 00, 01, 00, 00, 00, 01, 00, 00, 00, 05,
00, 00, 00), class = "bigz")

... maxas.numeric (实际上, as.double )具有用于 bigz 的方法类,但显然 as.integer才不是:
> methods(max)
[1] max.bigq max.bigz
> methods(as.numeric)
no methods were found
> methods(as.double)
[1] as.double.bigq as.double.bigz as.double.difftime as.double.POSIXlt
> methods(as.integer)
no methods were found

...所以 as.integer对待 bigz对象作为简单的值向量。

关于r - as.integer(max(factorize(15))) 的评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7571409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com