Apply function for data underlying disto object
dapply(x, margin = 1, fun, subset, nproc = 1, progress)
x | disto object |
---|---|
margin | (one among 1 or 2) dimension to apply function along |
fun | Function to apply over the margin |
subset | (integer vector) Row/Column numbers along the margin. If this is missing, all rows or columns are considered |
nproc | Number of parallel processes (unix only) |
progress | (flag) Whether to show the progress bar or not. If missing and if the length of the subset is at least 1e4, progress is considered to be TRUE. |
A list
fun should accept two arguments(in the same order): First, a vector of distances (row or column of a disto depending on the margin). Second, the row or the column number. See the example below
#> Error: Unable to find the object in the specified environment.# function to pick unsorted indexes of 5 nearest neighbors (excepting itself) udf_nn <- function(distances, index){ nnPlusOne <- which( data.table::frankv(distances, ties.method = "dense") <= 6) setdiff(nnPlusOne, index) } hi <- dapply(dio, 1, udf_nn)#> Error in inherits(x, "disto"): object 'dio' not foundhead(hi)#> Error in head(hi): object 'hi' not found#> Error in lapply(X = X, FUN = FUN, ...): object 'hi' not found