Using R, is there a way to take a data set and map out every possible combination of every categorical variable?
For example, let\'s say I had 10,000 rows of custom
Create some dummy data:
dataset <- data.frame(
spend=10*runif(100),
email=sample(c("yahoo","gmail","hotmail","aol"),100,replace=TRUE),
browser=sample(c("Mozilla","IE","Chrome","Opera"),100,replace=TRUE),
country=sample(c("USA","Canada","China","Australia",
"Egypt","S.Korea","Brazil"),100,replace=TRUE))
Average the spend
per combination:
with(dataset,by(spend,list(email,browser,country),mean))
Note the NA
s for combinations without entries.
Or turn this into a three-dimensional array
:
as.table(with(dataset,by(spend,list(email,browser,country),mean)))