[R-sig-hpc] Question

"Jens Oehlschlägel" jens.oehlschlaegel at truecluster.com
Sun Aug 21 18:26:23 CEST 2011


You asked how to do


with ff objects.

You can do that by storing the logical selection in a bit vector and then creating the target ff vector in the final size
n <- 4e7
s <- 1e3
a <- ff(1:n, caching="mmeachflush")
  # creating the boolean vector
  f <- bit(n)
  for (i in chunk(a, by=s)) f[i] <- a[i]>5
  # now knowing the desires length create the target ff
  b <- clone(a, length=sum(f), update=FALSE)
  # fill it using the evaluated condition
  n1 <- 0L
  for (i in chunk(a, by=s)){
    h <- as.hi(f, range=i)
    n2 <- n1 + length(h)
    n1 <- n1 + 1L
    b[n1:n2] <- a[h]
    n1 <- n2

However you can also save the RAM for the bit vector and - more important - a second pass over the input data by growing the target ff on the fly:

  for (i in chunk(a, by=s))
    x <- a[i]
    x <- x[x>5]
    if (i[[1]]==1L){
      b <- as.ff(x, caching="mmeachflush")
      n1 <- length(b)
      n2 <- n1 + length(x)
      length(b) <- n2
      n1 <- n1 + 1L
      b[n1:n2] <- x

The latter for me performs better if the ff object are bigger than RAM, the former might be better if you want to combine several logical conditions.

Kind regards

Jens Oehlschlägel

-----Ursprüngliche Nachricht-----
Von: kradlak <krystian.radlak at comarch.pl>
Gesendet: 18.08.2011 11:24:21
An: Jens.Oehlschlaegel at truecluster.com
Betreff: Question

> Hi,
>I have a question connected to package ff.
>I want to do operation with ff vector from packages ff like simple
>operation in R like this.
>How to do this operation with ff packages:
>Example :
>a=ff(1, length=15*10^7)
>I know that I could get logical vector like this:
>k=bit(15*10^7) # from bit packages
> for (i in chunk(a)){ k[i]<- a[i]<1}
>Any suggestions?


More information about the R-sig-hpc mailing list