Skip to content

Instantly share code, notes, and snippets.

@xxyjoel
Created June 6, 2018 00:22
Show Gist options
  • Save xxyjoel/10deca646bc875792152c4d882236200 to your computer and use it in GitHub Desktop.
Save xxyjoel/10deca646bc875792152c4d882236200 to your computer and use it in GitHub Desktop.
require(arules)
require(arulesViz)
require(reshape2)
require(gender)
require(plyr)
require(dplyr)
require(ggplot2)
transaction.data <- read.csv('fact table; transaction data with first and last customer names')
customer.data <- read.csv('dim table; Customer information')
customer.transaction.data <-
merge(x = customer.data, y = transaction.data, by.x = 'Square.Customer.ID',
by.y = 'Customer.ID')
first.names <- as.character(as.vector(customer.data$First.Name))
last.name <- as.character(as.vector(customer.data$Last.Name))
gender <- gender(first.names, method = "ssa")
gender <- gender[!duplicated(gender), ]
customer.data.wgender <-
merge(x = customer.data, y = gender, by.x = 'First.Name', by.y = 'name')
customer.transaction.data.w.gender <-
merge(x = customer.data.wgender, y = transaction.data, by.x = 'Square.Customer.ID',
by.y = 'Customer.ID')
males <- subset(customer.data.wgender, gender == "male")
females <- subset(customer.data.wgender, gender == "female")
unique.gender.qty <- data.frame(gender = c("Male", "Female"),
unique.qty = c(nrow(males), nrow(females)))
ggplot(unique.gender.qty, aes(gender , unique.qty, fill = gender)) +
geom_col()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment