
The generic swap
combines x[i]
and x[i] <- value
in a single operation.
swap(x, value, …)
# S3 method for ff
swap(x, value, i, add = FALSE, pack = FALSE, …)
# S3 method for ff_array
swap(x, value, …, bydim = NULL, drop = getOption("ffdrop"), add = FALSE, pack = FALSE)
# S3 method for default
swap(x, value, …, add = FALSE)
a ff or ram object
the new values to write, possibly recycled, see [.ff
index information, see [.ff
missing OR up to length(dim(x)) index expressions OR (ff only) hi
objects
logical scalar indicating whether array dimensions shall be dropped
how to interpret vector to array data, see [.ff
TRUE if the values should rather increment than overwrite at the target positions, see readwrite.ff
FALSE to prevent rle-packing in hybrid index preprocessing, see as.hi
Values at the target positions.
More precisely swap(x, value, i, add=FALSE)
returns the old values at the position i
while swap(x, value, i, add=TRUE)
returns the incremented values of x
.
y <- swap(x, value, i, add=FALSE, ...)is a shorter and more efficient version of
y <- x[i, add=FALSE, ...] x[i, add=FALSE, ...] <- value
and
y <- swap(x, value, i, add=TRUE, ...)
is a shorter and more efficient version of
y <- x[i, add=TRUE, ...] y <- y + value x[i, add=FALSE, ...] <- y
# NOT RUN {
x <- ff("a", levels=letters, length=52)
y <- swap(x, "b", sample(length(x), 26))
x
y
rm(x,y); gc()
# }
Run the code above in your browser using DataLab