1

I am trying to substitute values of an ff vector using two other vectors. With RAM objects it is straightforward:

w <- 3:6; w1 = 1:10; w2 = letters[1:10]
# a way to do it:
sapply(w, FUN=function(x){ w2[which(w1 == x)] } )
[1] "c" "d" "e" "f"

ff objects:

require(ff); require(ffbase)
z <- ff(3:6); z1 = ff(1:10); z2 = ff(factor(letters[1:10]))

How could I use ffvecapply (or any other function) to achieve the result:

> z
ff (open) integer length=4 (4) levels: c d e f
[1] [2] [3] [4] 
 c   d   e   f

I have checked this post, but

z <- ff(3:6)
y <- ff(z[], dim = c(1, 4))
z1 = ff(1:10); z2 = ff(factor(letters[1:10]))
y = as.ffdf(y)
lapply(physical(y), FUN=function(x){ z2[ffwhich(z1, z1 == x)] } )

Returns an error. Many thanks.

Community
  • 1
  • 1
Audrey
  • 212
  • 4
  • 15
  • 1
    I you use ffwhich, you need to make sure you handle the case where ffwhich returns something of length 0 as your selection does not return anything. Also == which you use in ffwhich is not implementend for ff_array's which you created in y. Only for ff vectors. I advise to print the results of ffwhich in your FUN to see what is in there. –  Jul 04 '14 at 08:14
  • Thanks Jan. Point taken regarding == on arrays. A question is, is it possible to somehow 'translate' a lookup function to a lookup expression, so we can make use of `ffvecapply`? – Audrey Jul 04 '14 at 08:37

0 Answers0