fwhich {filearray} | R Documentation |
A generic function of which
that is 'FileArray'
compatible
Description
A generic function of which
that is 'FileArray'
compatible
Usage
fwhich(x, val, arr.ind = FALSE, ret.values = FALSE, ...)
## Default S3 method:
fwhich(x, val, arr.ind = FALSE, ret.values = FALSE, ...)
## S3 method for class 'FileArray'
fwhich(x, val, arr.ind = FALSE, ret.values = FALSE, ...)
Arguments
x |
any R vector, matrix, array or file-array |
val |
values to find, or a function taking one argument (a slice of data vector) and returns either logical vector with the same length as the slice or index of the slice; see 'Examples' |
arr.ind |
logical; should array indices be
returned when |
ret.values |
whether to return the values of corresponding indices as an attributes; default is false |
... |
passed to |
Value
The indices of x
elements that are listed in val
.
Examples
# ---- Default case ------------------------------------
x <- array(1:27 + 2, rep(3,3))
# find index of `x` equal to either 4 or 5
fwhich(x, c(4,5))
res <- fwhich(x, c(4,5), ret.values = TRUE)
res
attr(res, "values")
# ---- file-array case --------------------------------
arr <- filearray_create(tempfile(), dim(x))
arr[] <- x
fwhich(arr, c(4,5))
fwhich(arr, c(4,5), arr.ind = TRUE, ret.values = TRUE)
arr[2:3, 1, 1]
# Clean up this example
arr$delete()
# ---- `val` is a function ----------------------------
x <- as_filearray(c(sample(15), 15), dimension = c(4,4))
ret <- fwhich(x, val = which.max,
ret.values = TRUE, arr.ind = FALSE)
# ret is the index
ret == which.max(x[])
# attr(ret, "values") is the max value
max(x[]) == attr(ret, "values")
# customize `val`
fwhich(x, ret.values = TRUE, arr.ind = FALSE,
val = function( slice ) {
slice > 10 # or which(slice > 10)
})
[Package filearray version 0.1.7 Index]