Created
February 16, 2017 06:41
-
-
Save Keiku/694fa31b96c44c11bcfdba848cee212c to your computer and use it in GitHub Desktop.
Check duplicate id list of some tables.
This file contains hidden or 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
library(gplots) | |
library(dplyr) | |
library(magrittr) | |
check_id_sets <- function(ids){ | |
ids_venn <- gplots::venn(ids, show.plot=FALSE) | |
ids_list <- unlist(as.list(ids_venn)) | |
mat_dim <- c((length(ids_list) / (length(ids)+1)), length(ids)+1) | |
id_sets <- ids_list %>% | |
matrix(., mat_dim) %>% | |
dplyr::as_data_frame(.) %>% | |
magrittr::set_names(c("num", names(ids))) %>% | |
dplyr::mutate(set = row.names(ids_venn)) %>% | |
dplyr::select_(.dots = c("set", "num", names(ids))) | |
return(id_sets) | |
} | |
ID1 <- c(1:10) | |
ID2 <- c(5:15) | |
ID3 <- c(10:20) | |
ID_list <- list(ID1=ID1, ID2=ID2, ID3=ID3) | |
check_id_sets(ID_list) | |
# A tibble: 8 × 5 | |
# set num ID1 ID2 ID3 | |
# <chr> <dbl> <dbl> <dbl> <dbl> | |
# 1 000 0 0 0 0 | |
# 2 001 5 0 0 1 | |
# 3 010 0 0 1 0 | |
# 4 011 5 0 1 1 | |
# 5 100 4 1 0 0 | |
# 6 101 0 1 0 1 | |
# 7 110 5 1 1 0 | |
# 8 111 1 1 1 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment