O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example – Using SQL to get sales by region

In this example, we will use the R package sqldf to show the difference in sales and units in four sales regions. Note that this is an artificial example since we will first generate separate data for the West region with sales figures that are higher than the other three regions:

install.packages("sqldf") library(sqldf) set.seed(10) rows=100 y <- rbind( data.frame(indv=factor(paste("TransId-", 1:100, sep = "")),                 Sales=rnorm(rows, mean=1500000,sd=100000),                 Units=round(rnorm(rows,mean=10, sd=3)),                 Region=sample(c("North","East","South"),rows, replace=TRUE)), data.frame(indv=factor(paste("TransId-", 101:200, sep = "")),                 Sales=rnorm(rows, mean=2000000,sd=100000),  Units=round(rnorm(rows,mean=10, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required