[英]Character vectors as ff objects in R
I am trying to convert a standard (RAM) character vector to an ff object (vector). 我正在尝试将标准(RAM)字符向量转换为ff对象(向量)。 The code below returns an error:
下面的代码返回错误:
> as.ff(c('a', 'b'))
Error in ff(initdata = initdata, length = length, levels = levels, ordered = ordered,:
vmode 'character' not implemented
This thread ( https://stackoverflow.com/questions/17744525/r-difficulties-facing-with-read-csv-ffdf-physicalmode-and-virtualmode ) suggests that ff objects do not accept characters at all, only factors. 该线程( https://stackoverflow.com/questions/17744525/r-difficulties-face-with-read-csv-ffdf-physicalmode-and-virtualmode )表明ff对象根本不接受字符,仅是因素。 Still, the below does not work:
不过,以下操作无效:
> as.ff(c('a', 'b'), vmode = 'factor')
Error in ff(initdata = initdata, length = length, levels = levels, ordered = ordered,:
vmode 'factor' not implemented
The list below does not include 'factors': 以下列表不包括“因素”:
.vimplemented
boolean logical quad nibble byte ubyte short ushort
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
integer single double complex raw character
TRUE TRUE TRUE FALSE TRUE FALSE
So is it possible at all to create an ff vector of characters? 那么有可能创建一个ff个字符向量吗?
Curently, in ff, pure character vectors are not implemented. 当前,在ff中,没有实现纯字符向量。 Factors are.
因素是。 As c('a','b') is a character, it will not work to convert it to ff.
由于c('a','b')是一个字符,因此无法将其转换为ff。 But it is of course possible to convert factors to ff.
但是,当然可以将因子转换为ff。
require(ff)
class(c('a', 'b'))
[1] "character"
class(factor(c('a', 'b')))
[1] "factor"
as.ff(factor(c('a', 'b')))
ff (open) integer length=2 (2) levels: a b
[1] [2]
a b
class(as.ff(factor(c('a', 'b'))))
[1] "ff_vector" "ff"
Mark also that the factor levels are in RAM. 还标记因子级别在RAM中。 All the rest is on disk.
其余所有磁盘上。
Just call factor
on your variable: 只需对变量调用
factor
:
as.ff(factor(c('a', 'b')))
ff (open) integer length=2 (2) levels: a b
[1] [2]
a b
Internally, factors are integers, 在内部,因子是整数,
storage.mode(factor(c('a', 'b')))
[1] "integer"
with a levels
attribute that maps to the character representation. 具有可映射到字符表示形式的
levels
属性。 As you noted, integers are supported by ff
. 如您所述,
ff
支持整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.