Last active
December 27, 2016 06:14
-
-
Save JakeConway/eb4d34b54302f1349f0a to your computer and use it in GitHub Desktop.
Convert list of named vectors to UpSetR input
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
fromList <- function(input){ | |
elements <- unique(unlist(input)) | |
data <- unlist(lapply(input, function(x){x <- as.vector(match(elements, x))})) | |
data[is.na(data)] <- as.integer(0); data[data != 0] <- as.integer(1) | |
data <- data.frame(matrix(data, ncol = length(input), byrow = F)) | |
data <- data[which(rowSums(data) !=0), ] | |
names(data) <- names(input) | |
return(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment