Quantcast

Binning Data and Event rates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Binning Data and Event rates

prateek
I have a data, in the form mentioned below.

Values Churn
21          1
22          1
31.2       1
32          1
35          0
43          1
45           0
67          1
67           0
76           0
89           1

Now i want to bin the values variables into bins and corresponding that
want the churn percentage, like mentioned below
   Binned data  churn%
  (20.9,43.7]    0.83
  (43.7,66.3]    0
  (66.3,89.1]    0.50

Please help

« Return to Rcom-l <http://r.789695.n4.nabble.com/Rcom-l-f930477.html>  |  3
v

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Binning Data and Event rates

Jim Lemon-4
Hi Pateek,
Try this:
ppdat<-read.table(text="Values Churn
 21          1
 22          1
 31.2       1
 32          1
 35          0
 43          1
 45           0
 67          1
 67           0
 76           0
 89           1",
 header=TRUE)
ppdat$Valbin<-cut(ppdat$Values,breaks=c(20.9,43.7,66.3,89.1))
binPct<-function(x) return(100*sum(x)/length(x))
binnedPct<-by(ppdat$Churn,ppdat$Valbin,binPct)
bpctdf<-data.frame('Binned data'=names(binnedPct),
 'churn%'=as.vector(binnedPct))
bpctdf

Jim

On Tue, Apr 18, 2017 at 5:20 AM, prateek pande <[hidden email]> wrote:

> I have a data, in the form mentioned below.
>
> Values Churn
> 21          1
> 22          1
> 31.2       1
> 32          1
> 35          0
> 43          1
> 45           0
> 67          1
> 67           0
> 76           0
> 89           1
>
> Now i want to bin the values variables into bins and corresponding that
> want the churn percentage, like mentioned below
>    Binned data  churn%
>   (20.9,43.7]    0.83
>   (43.7,66.3]    0
>   (66.3,89.1]    0.50
>
> Please help
>
> « Return to Rcom-l <http://r.789695.n4.nabble.com/Rcom-l-f930477.html>  |  3
> v
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Binning Data and Event rates

David Carlson
After creating ppdat and ppdat$Valbin, aggregate() will get you the churn proportions:

> aggregate(Churn~Valbin, ppdat, mean)
       Valbin     Churn
1 (20.9,43.7] 0.8333333
2 (43.7,66.3] 0.0000000
3 (66.3,89.1] 0.5000000


David L. Carlson
Department of Anthropology
Texas A&M University


-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of Jim Lemon
Sent: Monday, April 17, 2017 4:59 PM
To: prateek pande <[hidden email]>
Cc: r-help mailing list <[hidden email]>
Subject: Re: [R] Binning Data and Event rates

Hi Pateek,
Try this:
ppdat<-read.table(text="Values Churn
 21          1
 22          1
 31.2       1
 32          1
 35          0
 43          1
 45           0
 67          1
 67           0
 76           0
 89           1",
 header=TRUE)
ppdat$Valbin<-cut(ppdat$Values,breaks=c(20.9,43.7,66.3,89.1))
binPct<-function(x) return(100*sum(x)/length(x))
binnedPct<-by(ppdat$Churn,ppdat$Valbin,binPct)
bpctdf<-data.frame('Binned data'=names(binnedPct),
 'churn%'=as.vector(binnedPct))
bpctdf

Jim

On Tue, Apr 18, 2017 at 5:20 AM, prateek pande <[hidden email]> wrote:

> I have a data, in the form mentioned below.
>
> Values Churn
> 21          1
> 22          1
> 31.2       1
> 32          1
> 35          0
> 43          1
> 45           0
> 67          1
> 67           0
> 76           0
> 89           1
>
> Now i want to bin the values variables into bins and corresponding that
> want the churn percentage, like mentioned below
>    Binned data  churn%
>   (20.9,43.7]    0.83
>   (43.7,66.3]    0
>   (66.3,89.1]    0.50
>
> Please help
>
> « Return to Rcom-l <http://r.789695.n4.nabble.com/Rcom-l-f930477.html>  |  3
> v
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...