The following is the code I want to run. This is a code from Coursera. I am unable to run the sqldf function in this code:-
data = read.delim(file = 'purchases.txt', header = FALSE, sep = '\t', dec = '.')
str(data)
colnames(data) = c('customer_id', 'purchase_amount', 'date_of_purchase')
data$date_of_purchase = as.Date(data$date_of_purchase, "%Y-%m-%d")
data$days_since = as.numeric(difftime(time1 = "2016-01-01",
time2 = data$date_of_purchase,
units = "days"))
head(data)
summary(data)
library(sqldf)
customers = sqldf("SELECT customer_id ,
MIN(days_since) AS 'recency',
COUNT(*) AS 'frequency',
AVG(purchase_amount) AS 'amount'
FROM data GROUP BY 1")