Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Last active November 30, 2015 15:22
Show Gist options
  • Save jmcastagnetto/6f9f4d3a5627e5ee33f5 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/6f9f4d3a5627e5ee33f5 to your computer and use it in GitHub Desktop.
# Inspired by http://xkcd.com/1609/
set.seed(1609)
food <- c("ice cream", "ham", "relish",
"pancakes", "ketchup", "cheese",
"eggs", "cupcakes", "sour cream",
"hot chocolate", "avocado", "skittles",
"wasabi", "tofu", "steak", "sweet potatoes")
nfood <- length(food)
food_combination <- function(x) {
i <- sample(1:nfood, 1)
t_food <- food[-i]
j <- sample(1:length(t_food), 1)
f1 <- food[i]
f2 <- t_food[j]
sprintf("(%d) You know what's actually really good? %s and %s", x, f1, f2)
}
sapply(1:10, "food_combination")
# a variation that shows the frequency of combinations
set.seed(1609)
food <- c("ice cream", "ham", "relish",
"pancakes", "ketchup", "cheese",
"eggs", "cupcakes", "sour cream",
"hot chocolate", "avocado", "skittles",
"wasabi", "tofu", "steak", "sweet potatoes")
nfood <- length(food)
food_combination2 <- function(x) {
i <- sample(1:nfood, 1)
t_food <- food[-i]
j <- sample(1:length(t_food), 1)
f1 <- food[i]
f2 <- t_food[j]
c(food1=f1, food2=f2)
}
combos <- as.data.frame(t(sapply(1:10000, "food_combination2")))
combos_freq <- as.data.frame(table(combos$food1, combos$food2))
library(ggplot2)
ggplot(combos_freq, aes(Var1, Var2)) +
geom_tile(aes(fill=Freq), colour="white") +
scale_fill_gradient(low = "white", high="red")
# Some combinations are interesting like "eggs and wasabi" or "sweet potatoes and sourcream", others are
# marginal like "cheese and skittles"
@jmcastagnetto
Copy link
Author

food-combinations2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment