문제

I am trying to convert a standard (RAM) character vector to an ff object (vector). 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. 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?

도움이 되었습니까?

해결책

Curently, in ff, pure character vectors are not implemented. Factors are. As c('a','b') is a character, it will not work to convert it to ff. But it is of course possible to convert factors to 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. All the rest is on disk.

다른 팁

Just call factor on your variable:

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. As you noted, integers are supported by ff.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top