Sorting: order from ff vectors
fforder.rdReturns order with regard to one or more ff vectors
Usage
fforder(...
, index = NULL
, use.index = NULL
, aux = NULL
, auxindex = NULL
, has.na = TRUE
, na.last = TRUE
, decreasing = FALSE
, BATCHBYTES = getOption("ffmaxbytes")
, VERBOSE = FALSE
)Arguments
- ...
one of more ff vectors which define the order
- index
an optional ff integer vector used to store the order output
- use.index
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.
- aux
An optional named list of ff vectors that can be used for temporary copying – the names of the list identify the
vmodesfor which the respective ff vector is suitable.- auxindex
An optional ff intger vector for temporary storage of integer positions.
- has.na
boolean scalar telling fforder whether the vector might contain
NAs. Note that you risk a crash if there are unexpectedNAs withhas.na=FALSE- na.last
boolean scalar telling fforder whether to order
NAs last or first. Note that 'boolean' means that there is no third optionNAas inorder- decreasing
boolean scalar telling fforder whether to order increasing or decreasing
- BATCHBYTES
maximum number of RAM bytes fforder should try not to exceed
- VERBOSE
cat some info about the ordering
Details
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.
Value
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 ...
Examples
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 1246647 66.6 2239654 119.7 2239654 119.7
#> Vcells 2292819 17.5 8388608 64.0 8387257 64.0