[R] ffbase, help with %in%

Christiaan Pauw cjpauw at gmail.com
Mon Oct 1 22:35:51 CEST 2012


Hi Lucas

I don't know the ff package very well but here is what I found. Maybe
there is a clue in here

> z   <- as.Date("1970-01-01")+1:10
> zff <- as.ff(z)
> z %in% zff

 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

#but
> z %in% zff[1:length(zff),]
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
# and also
> z %in% zff[1:10]
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

That seems to be because an ff object is a list

> str(zff)
 list()
 - attr(*, "physical")=Class 'ff_pointer' <externalptr>
  ..- attr(*, "vmode")= chr "double"
  ..- attr(*, "maxlength")= int 10
  ..- attr(*, "pattern")= chr "clone"
  ..- attr(*, "filename")= chr
"/private/var/folders/ub/ubvWLUkKHf8WAywv5rmtcE+++TI/-Tmp-/RtmpmMKHRx/clone406828b135cc.ff"
  ..- attr(*, "pagesize")= int 65536
  ..- attr(*, "finalizer")= chr "close"
  ..- attr(*, "finonexit")= logi TRUE
  ..- attr(*, "readonly")= logi FALSE
  ..- attr(*, "caching")= chr "mmnoflush"
 - attr(*, "virtual")= list()
  ..- attr(*, "Length")= int 10
  ..- attr(*, "Symmetric")= logi FALSE
  ..- attr(*, "ramclass")= chr "Date"
 - attr(*, "class") =  chr [1:2] "ff_vector" "ff"

If you make a data frame e.g
df <- data.frame(date=z,letter=letters[1:10])
# this doesn't work
> as.ff(df[1:10,1])%in% z
logical(0)
# but this does
> as.ff(df[1:10,1]%in% z)
ff (open) logical length=10 (10)
 [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9] [10]
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

The question is: In your example, do you want "a" to be a ff object or
the first column of data to be an ff object (I could get this to work
- propably for the reasons above :
> df <- data.frame(date=as.ff(z),letter=letters[1:10])
Error in as.data.frame.default(x[[i]], optional = TRUE,
stringsAsFactors = stringsAsFactors) :
  cannot coerce class 'c("ff_vector", "ff")' into a data.frame

On 1 October 2012 20:07, Lucas Chaparro <lpchaparrovio at gmail.com> wrote:
> Hello to everyone.
> I'm trying to use the %in% to match to vectors in ff format.
> a<-as.ff(data[,1]) %in% fire$fecha
>
>> aff (open) logical length=3653 (3653)
>    [1]    [2]    [3]    [4]    [5]    [6]    [7]    [8]        [3646]
>  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE      :  FALSE
> [3647] [3648] [3649] [3650] [3651] [3652] [3653]
>  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE  FALSE
>
>
> Here you see a part of the data:
>
> data[1:20,]  (just a sample, data has 3653 obs)
>
>         fecha juliano altura  UTM.E   UTM.N
> 1  1990-07-01     182     15 248500 6239500
> 2  1990-07-02     183     15 248500 6239500
> 3  1990-07-03     184     15 248500 6239500
> 4  1990-07-04     185     15 248500 6239500
> 5  1990-07-05     186     15 248500 6239500
> 6  1990-07-06     187     15 248500 6239500
> 7  1990-07-07     188     15 248500 6239500
> 8  1990-07-08     189     15 248500 6239500
> 9  1990-07-09     190     15 248500 6239500
> 10 1990-07-10     191     15 248500 6239500
> 11 1990-07-11     192     15 248500 6239500
> 12 1990-07-12     193     15 248500 6239500
> 13 1990-07-13     194     15 248500 6239500
> 14 1990-07-14     195     15 248500 6239500
> 15 1990-07-15     196     15 248500 6239500
> 16 1990-07-16     197     15 248500 6239500
> 17 1990-07-17     198     15 248500 6239500
> 18 1990-07-18     199     15 248500 6239500
> 19 1990-07-19     200     15 248500 6239500
> 20 1990-07-20     201     15 248500 6239500
>
>
>> fire$fecha[1:20,] [1] "1984-11-08" "1984-11-08" "1984-11-09" "1984-11-09" "1984-11-09"
>  [6] "1984-11-10" "1984-11-10" "1984-11-11" "1984-11-11" "1984-11-11"
> [11] "1984-11-11" "1984-11-11" "1984-11-11" "1984-11-12" "1984-11-12"
> [16] "1984-11-13" "1984-11-13" "1984-11-13" "1984-11-14" "1984-11-14"
>
>
> to see if a got any match:
>
>
> table.ff(a)
>
>
> FALSE  TRUE
>  1687  1966 Mensajes de aviso perdidosIn if (useNA == "no") c(NA, NaN) :
>   la condición tiene longitud > 1 y sólo el primer elemento será usado
>
>
> in a regular data.frame I use data[a,] to extract the rows that a ==
> TRUE, but when i do this in a ffdf i get this error:
>
>
>> data[a,]Error: vmode(index) == "integer" is not TRUE
>
>
> I'm just learning how to use the ff package so, obviously I'm missing something
>
>
> If any of you knows how to solve this, please teach me.
>
> Thank you so much.
>
>
> Lucas.
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Christiaan Pauw
Nova Institute
www.nova.org.za




More information about the R-help mailing list