Skip to content

Instantly share code, notes, and snippets.

@JakeConway
Last active December 27, 2016 06:14
Show Gist options
  • Save JakeConway/eb4d34b54302f1349f0a to your computer and use it in GitHub Desktop.
Save JakeConway/eb4d34b54302f1349f0a to your computer and use it in GitHub Desktop.
Convert list of named vectors to UpSetR input
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