2

Is there a way to do simple arithmetic operations on ff class matrices? i.e. something like this:

> library(ff)
> a = ff(1, vmode = "double", dim = c(3,4))
> b = ff(2, vmode = "double", dim = c(3,4))
> a+b
Error in a + b : non-numeric argument to binary operator

I know ffbase can do this on vectors, but haven't found anything for matrices. Thanks.

1 Answers1

0

Reading ?LimWarn I see a details section entitled "Multiple vector interpretation in arrays" whose penultimate sentence is:

To access the array elements in R standard dimorder you simply use [ which dispatches to [.ff_array.

a[]+b[]
     [,1] [,2] [,3] [,4]
[1,]    3    3    3    3
[2,]    3    3    3    3
[3,]    3    3    3    3

(The results is an not an ff-object.)

Or, as hinted at in ?ff:

as.ram(a) +as.ram(b)
     [,1] [,2] [,3] [,4]
[1,]    3    3    3    3
[2,]    3    3    3    3
[3,]    3    3    3    3
attr(,"physical")
(hidden, use physical(x) to access the physical attributes and vmode(x) for accessing vmode)
attr(,"virtual")
(hidden, use virtual(x) to access the virtual attributes)
attr(,"vmode")
[1] "double"

(The result is an ff-object.)

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 2
    neither of the two would work on large objects (i.e. exactly what you need ff for) as the system will try to allocate vectors in memory which are too large. if you change the dimensions in my example to e.g. dim = c(3e4,4e3), you'd get Error: cannot allocate vector of size 915.5 Mb – user2835260 Oct 02 '13 at 07:50