-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ecohealthalliance/patch/set_diff
Patch/set diff
- Loading branch information
Showing
6 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' Get items that differ between x and y | ||
#' | ||
#' Unlike setdiff, this function creates the union of x and y then | ||
#' removes values that are in the intersect, providing values | ||
#' that are unique to X and values that are unique to Y. | ||
#' | ||
#' @param x a set of values. | ||
#' @param y a set of values. | ||
#' | ||
#' @return Unique values from X and Y, NULL if no unique values. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' a <- 1:3 | ||
#' b <- 2:4 | ||
#' | ||
#' set_diff(a,b) | ||
#' # returns 1,4 | ||
#' | ||
#' x <- 1:3 | ||
#' y <- 1:3 | ||
#' | ||
#' set_diff(x,y) | ||
#' # returns NULL | ||
#' | ||
set_diff <- function(x,y){ | ||
u <- union(x,y) | ||
i <- intersect(x,y) | ||
j <- (u %in% i) | ||
|
||
if(all(j)){ | ||
return(NULL) | ||
} | ||
|
||
diff <- u[!(j)] | ||
return(diff) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.