【问题标题】:R::bigmemory - how to create character big.matrix?R::bigmemory - 如何创建字符 big.matrix?
【发布时间】:2012-11-27 10:52:43
【问题描述】:

我尝试在 R 中使用bigmemory 包,但我一开始就被卡住了。我愿意:

temp <- matrix(paste("a",1:10), 5, 2)

并得到一个字符矩阵。没关系。但后来我尝试:

x <- as.big.matrix(temp, type="char")

我得到一个充满 NA 的矩阵和以下消息:

Assignment will down cast from double to char
Hint: To remove this warning type:  options(bigmemory.typecast.warning=FALSE)
Warning messages:
1: In as.big.matrix(temp, type = "char") : Casting to numeric type
2: In matrix(as.numeric(x), nrow = nrow(x), dimnames = dimnames(x)) :
NAs introduced by coercion
3: In SetElements.bm(x, i, j, value) :

我不确定发生了什么,但它看起来很大。尽管type = "char",matrix 仍试图将我的所有文本转换为数字。如何让它发挥作用?

【问题讨论】:

    标签: r matrix character r-bigmemory


    【解决方案1】:

    这有点用词不当 - big.matrix 对象只存储数字数据类型。 'char' 类型是一种 C++ 数据类型,用于存储表示 ASCII 字符代码(单个字符,而不是字符串)的整数值。要将字符串存储在 big.matrix 中,您必须将字符串重新编码为数值(或转换为因子,然后转换为数值)。

    如果您需要将字符数据存储在非常大的数据集中,您可能需要查看“ff”包。根据我的经验,它有一个陡峭的学习曲线,并且文档有些缺乏,但它确实具有该功能。

    有关处理大型数据集的更多详细信息,您可以在此处查看 CRAN 任务视图:http://cran.r-project.org/web/views/HighPerformanceComputing.html

    【讨论】:

    • 非常感谢。现在我明白了。
    猜你喜欢
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2012-01-09
    • 2021-12-16
    相关资源
    最近更新 更多