fforder.rdReturns order with regard to one or more ff vectors
fforder(...
, index = NULL
, use.index = NULL
, aux = NULL
, auxindex = NULL
, has.na = TRUE
, na.last = TRUE
, decreasing = FALSE
, BATCHBYTES = getOption("ffmaxbytes")
, VERBOSE = FALSE
)one of more ff vectors which define the order
an optional ff integer vector used to store the order output
A boolean flag telling fforder whether to use the positions in 'index' as input. If you do this, it is your responsibility to assure legal positions - otherwise you risk a crash.
An optional named list of ff vectors that can be used for temporary copying
– the names of the list identify the vmodes for which the respective ff vector is suitable.
An optional ff intger vector for temporary storage of integer positions.
boolean scalar telling fforder whether the vector might contain NAs.
Note that you risk a crash if there are unexpected NAs with has.na=FALSE
boolean scalar telling fforder whether to order NAs last or first.
Note that 'boolean' means that there is no third option NA as in order
boolean scalar telling fforder whether to order increasing or decreasing
maximum number of RAM bytes fforder should try not to exceed
cat some info about the ordering
fforder tries to order the vector in-RAM, if not possible it uses (a yet simple) out-of-memory algorithm.
Like ramorder the in-RAM ordering method is choosen depending on context information.
An ff vector with the positions that ore required to sort the input as specified
– with an attribute na.count with as many values as columns in ...
x <- ff(sample(1e5, 1e6, TRUE))
y <- ff(sample(1e5, 1e6, TRUE))
d <- ffdf(x, y)
i <- fforder(y)
y[i]
#> ff (open) integer length=1000000 (1000000)
#> [1] [2] [3] [4] [5] [6] [7] [8]
#> 1 1 1 1 1 1 1 1
#> [999993] [999994] [999995] [999996] [999997] [999998] [999999]
#> : 100000 100000 100000 100000 100000 100000 100000
#> [1000000]
#> 100000
i <- fforder(x, index=i)
x[i]
#> ff (open) integer length=1000000 (1000000)
#> [1] [2] [3] [4] [5] [6] [7] [8]
#> 1 1 1 1 1 1 1 1
#> [999993] [999994] [999995] [999996] [999997] [999998] [999999]
#> : 100000 100000 100000 100000 100000 100000 100000
#> [1000000]
#> 100000
d[i,]
#> ffdf (all open) dim=c(1000000,2), dimorder=c(1,2) row.names=NULL
#> ffdf virtual mapping
#> PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix
#> x x integer integer FALSE FALSE
#> y y integer integer FALSE FALSE
#> PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol
#> x FALSE 1 1 1
#> y FALSE 2 1 1
#> PhysicalIsOpen
#> x TRUE
#> y TRUE
#> ffdf data
#> x y
#> 1 1 2209
#> 2 1 15556
#> 3 1 38650
#> 4 1 42592
#> 5 1 47528
#> 6 1 58202
#> 7 1 67100
#> 8 1 69662
#> : : :
#> 999993 100000 51225
#> 999994 100000 54259
#> 999995 100000 58982
#> 999996 100000 64533
#> 999997 100000 72528
#> 999998 100000 75553
#> 999999 100000 88491
#> 1000000 100000 89196
i <- fforder(x, y)
d[i,]
#> ffdf (all open) dim=c(1000000,2), dimorder=c(1,2) row.names=NULL
#> ffdf virtual mapping
#> PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix
#> x x integer integer FALSE FALSE
#> y y integer integer FALSE FALSE
#> PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol
#> x FALSE 1 1 1
#> y FALSE 2 1 1
#> PhysicalIsOpen
#> x TRUE
#> y TRUE
#> ffdf data
#> x y
#> 1 1 2209
#> 2 1 15556
#> 3 1 38650
#> 4 1 42592
#> 5 1 47528
#> 6 1 58202
#> 7 1 67100
#> 8 1 69662
#> : : :
#> 999993 100000 51225
#> 999994 100000 54259
#> 999995 100000 58982
#> 999996 100000 64533
#> 999997 100000 72528
#> 999998 100000 75553
#> 999999 100000 88491
#> 1000000 100000 89196
i <- ffdforder(d)
d[i,]
#> ffdf (all open) dim=c(1000000,2), dimorder=c(1,2) row.names=NULL
#> ffdf virtual mapping
#> PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix
#> x x integer integer FALSE FALSE
#> y y integer integer FALSE FALSE
#> PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol
#> x FALSE 1 1 1
#> y FALSE 2 1 1
#> PhysicalIsOpen
#> x TRUE
#> y TRUE
#> ffdf data
#> x y
#> 1 1 2209
#> 2 1 15556
#> 3 1 38650
#> 4 1 42592
#> 5 1 47528
#> 6 1 58202
#> 7 1 67100
#> 8 1 69662
#> : : :
#> 999993 100000 51225
#> 999994 100000 54259
#> 999995 100000 58982
#> 999996 100000 64533
#> 999997 100000 72528
#> 999998 100000 75553
#> 999999 100000 88491
#> 1000000 100000 89196
rm(x, y, d, i)
gc()
#> used (Mb) gc trigger (Mb) max used (Mb)
#> Ncells 1156577 61.8 1994352 106.6 1994352 106.6
#> Vcells 2152628 16.5 8790397 67.1 8790397 67.1