August 2018
Intermediate to advanced
378 pages
9h 9m
English
The code to create our ratings is in Chapter9/create_recommend.R. The first part of the code runs through the raw transactional data. The data is in separate CSV files, so it processes each file, selects the records that have a customer linked (that is, CUST_CODE!="") to them, and then groups the sales by CUST_CODE and PROD_CODE_40. It then appends the results to a temporary file and moves on to the next input file:
library(magrittr)library(dplyr)library(readr)library(broom)set.seed(42)file_list <- list.files("../dunnhumby/in/", "trans*")temp_file <- "../dunnhumby/temp.csv"out_file <- "../dunnhumby/recommend.csv"if (file.exists(temp_file)) file.remove(temp_file)if (file.exists(out_file)) file.remove(out_file)options(readr.show_progress=FALSE) ...Read now
Unlock full access