Skip to content

Instantly share code, notes, and snippets.

@dantalus
Last active May 6, 2016 05:37
Show Gist options
  • Save dantalus/357a06a84b7171e3f35d63788655d614 to your computer and use it in GitHub Desktop.
Save dantalus/357a06a84b7171e3f35d63788655d614 to your computer and use it in GitHub Desktop.
# frame.match ####
frame.match <- function(data.1, data.2, id.col, ...) {
# User defined for comparing dataframe cells
require(dplyr)
results <- list()
for (i in data.1[, id.col]) {
x <- rbind(filter(data.1, id == i), filter(data.2, id == i))
l <- list()
for (j in 1:length(x)){
l[[j]] <- identical(x[1, j], x[2, j])
}
y <- as.data.frame(do.call(cbind, l))
names(y) <- names(x)
results[[i]] <- y
}
results <- do.call(rbind, results)
results$id <- data.1[, id.col]
return(results)
}
frame.match(base.1, base.2, 1) %>%
gather(variable, match, 2:length(.)) %>%
mutate(variable = factor(variable, levels = names(base.1))) %>%
mutate(id = factor(id, levels = rev(levels(factor(id))))) %>%
ggplot(aes(x = variable, y = id, fill = match)) +
geom_tile(color = "grey50") +
scale_fill_viridis(discrete = TRUE) +
theme(panel.border = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_blank(),
axis.text.x = element_text (angle = 45, hjust = 1)) +
ylab("") +
xlab("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment