R :: bigmemory - 如何创建字符big.matrix? [英] R::bigmemory - how to create character big.matrix?
问题描述
我尝试在 R 中使用 bigmemory
包,我一开始就陷入困境。我这样做:
I try to use bigmemory
package in R and I'm stuck in the very beginning. I do:
temp <- matrix(paste("a",1:10), 5, 2)
并获得一个字符矩阵。没关系。但我尝试:
and get a character matrix. That's OK. But then I try:
x <- as.big.matrix(temp, type="char")
,我得到一个填充了NA的矩阵,并显示以下消息:
and I get a matrix full of NA and the following message:
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) :
我不知道发生了什么,但它看起来big.matrix试图将所有我的文本转换为数字,尽管 type =char
。如何使它工作?
I'm not sure what's going on but it looks big.matrix tries to convert all my texts in to numbers despite type = "char"
. How to make it work?
推荐答案
这是一个误解 - big.matrix对象只存储数字数据类型。 'char'类型是一种C ++数据类型,用于存储表示ASCII字符代码(单个字符,而不是字符串)的整数值。要将字符串存储在big.matrix中,您必须将字符串重新编码为数字值(或转换为因子,然后再转换为数字值)。
This is a bit of a misnomer - big.matrix objects only store numeric data types. The 'char' type is a C++ data type used to store integer values that represent ASCII character codes (a single character, not a character string). To store character strings in a big.matrix, you'll have to re-code the strings as numeric values (or convert to factors, then to numeric values).
如果你需要在一个非常大的数据集中存储字符数据,你可能需要查看'ff'包。在我的经验中,它有一个陡峭的学习曲线,文档有点缺乏,但它有这个功能。
If you need to store character data in a very large data set, you may want to look into the 'ff' package. In my experience it has a steep learning curve and the documentation is somewhat lacking, but it does have that functionality.
有关处理大型数据集的更多详细信息,请查看CRAN任务视图: http://cran.r-project.org/web/views/ HighPerformanceComputing.html
For further details on dealing with large data sets, you can check out the CRAN Task View here: http://cran.r-project.org/web/views/HighPerformanceComputing.html
这篇关于R :: bigmemory - 如何创建字符big.matrix?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!