Hi Prateek,
There is some difficulty with including the empty categories in the
factors generated. I couldn't get these even with drop=FALSE, so I had
to go through the "xtab" function. You can do it with the "table"
function in the base package, but it is a little more trouble. See if
this is what you want>
ppdat<-read.table(text="mou_mean,totalmrc_mean,rev_range,mou_range,Churn
23,24,25,27,1
45,46,47,49,1
43,44,45,47,1
45,46,47,49,0
56,57,58,60,0
67,68,69,71,1
67,68,69,71,0
44,45,46,48,1
33,34,35,37,0
90,91,92,94,1
87,88,89,91,1
76,77,78,80,1
33,34,35,37,1
44,45,46,48,1",
sep=",",header=TRUE)
ppdat$mou_mean_cut<-cut(ppdat$mou_mean,breaks=seq(23,103,10),include.lowest=TRUE)
ppdat$totalmrc_mean_cut<-cut(ppdat$totalmrc_mean,breaks=seq(23,103,10))
ppdat$rev_range_cut<-cut(ppdat$rev_range,breaks=seq(23,103,10))
ppdat$mou_range_cut<-cut(ppdat$mou_range,breaks=seq(23,103,10))
library(prettyR)
ppx<-xtab(Churn~mou_mean_cut,ppdat)
mou_mean_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
mou_mean_agg[is.nan(mou_mean_agg)]<-0
ppx<-xtab(Churn~totalmrc_mean_cut,ppdat)
totalmrc_mean_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
totalmrc_mean_agg[is.nan(totalmrc_mean_agg)]<-0
ppx<-xtab(Churn~rev_range_cut,ppdat)
rev_range_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
rev_range_agg[is.nan(rev_range_agg)]<-0
ppx<-xtab(Churn~mou_range_cut,ppdat)
mou_range_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
mou_range_agg[is.nan(mou_range_agg)]<-0
ppmat<-matrix(c(mou_mean_agg,totalmrc_mean_agg,rev_range_agg,
mou_range_agg),nrow=4,byrow=TRUE)
library(plotrix)
barp(ppmat,col=rainbow(4),main="Multiple histogram",ylim=c(0,105),
names.arg=levels(ppdat$mou_mean_cut),ylab="Percent churn")
legend(2.5,107,c("mou_mean","totalmrc_mean","rev_range","mou_range"),
fill=rainbow(4))
Jim