将 mpfr 对象的列表合并为单个 mpfr 向量

3

我一定是漏看了某些明显的东西:

library(Rmpfr)

list.mpfr <- list(mpfr(10, 128), mpfr(20, 128))  # I'd like to turn this into mpfr(c(10, 20), 128)
test <- c(list.mpfr, recursive=TRUE)  # Doesn't work -- should it?
identical(test, list.mpfr)  # False -- test is a list of mpfr1 and no longer a list of mpfr

## I'd expect c.mpfr(..., recursive=TRUE) to do the equivalent of c(list(1:5, 8:10), recursive=TRUE)
getAnywhere(c.mpfr)

我有一个返回长度为1的mpfr的函数。我使用mapply(..., simplify=FALSE)来构建类似于上面示例中的list.mpfr的东西。 我想将长度为1的mpfr对象组合成一个单一的mpfr对象(这样我就可以调用which.max,例如)。

1个回答

4

找到了解决方案:

library(Rmpfr)
list.mpfr <- list(mpfr(10, 128), mpfr(20, 128))
desired <- new("mpfr", unlist(list.mpfr))
identical(desired, mpfr(c(10, 20), 128))  # True

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接