ourMELONS/R/setdiff_MATLAB.R

16 lines
705 B
R
Raw Normal View History

#' @title Set differences of two arrays
#' @description Loosely replicates the behavior of the homonym Matlab function
#' @param A first array
2020-11-09 07:31:33 +01:00
#' @param B second array
#' @param legacy if `TRUE`, preserves the behavior of the setdiff function from MATLAB R2012b and prior releases. (currently not supported)
#' @author Waldir Leoncio
2020-10-19 15:57:15 +02:00
setdiff_MATLAB <- function(A, B, legacy = FALSE) {
2020-11-09 07:31:33 +01:00
if (legacy) message("legacy=TRUE not supported. Ignoring.")
2020-10-19 15:57:15 +02:00
if (is(A, "numeric") & is(B, "numeric")) {
values <- sort(unique(A[is.na(match(A, B))]))
} else if (is(A, "data.frame") & is(B, "data.frame")) {
stop("Not implemented for data frames")
}
# TODO: add support for indices (if necessary)
return(values)
}