Implemented dataframe parsing on setdiff

This commit is contained in:
Waldir Leoncio 2021-01-15 08:59:48 +01:00
parent 34cebe8604
commit d47b84fb55
2 changed files with 11 additions and 1 deletions

View file

@ -9,7 +9,16 @@ setdiff_MATLAB <- function(A, B, legacy = FALSE) {
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")
C <- A
exclude_rows <- vector()
for (r1 in seq_len(nrow(A))) {
for (r2 in seq_len(nrow(B))) {
if (all(A[r1, ] == B[r2, ])) {
exclude_rows <- append(exclude_rows, r1)
}
}
}
values <- C[-exclude_rows, ]
}
# TODO: add support for indices (if necessary)
return(values)