• R

# Binning Function in R

I've installed the rattle package and run this code.
``````library(rattle)
test <- c(1,2,3,4,5,6)
test
test2 <- binning(test,4,method = "quantile",ordered = FALSE)
test2
``````

This is the output I get.

``````[1] 1.000000 1.916667 3.500000 5.083333 6.000000
Levels: [1,1.92] (1.92,3.5] (3.5,5.08] (5.08,6]
``````
I understand that 3.5 is the median.  Where do 1.92 and 5.08 come from?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HelpDesk TechnicianCommented:
I believe those are your Lower (Q1) and Upper (Q3) Quartiles. Mathematically the function quantile() gives 9 different methods of computing quartiles. You results match the results of quantile() computed using method 8.

quantile(1:6,type=8)
0%      (Q1) 25%     50%    (Q3)75%     100%
1.000000 1.916667 3.500000 5.083333 6.000000

It's possible that the arguments in binning, potentially the method = "quantile" argument specifically, specify this method of computing quartiles.

Here is the documentation for that function in R: https://www.rdocumentation.org/packages/rattle/versions/5.2.0/topics/binning

I believe that "wtd.quantile" instead of "quantile" would potentially yield the expected and more common box-plot estimations of:
0%      (Q1) 25%     50%    (Q3)75%     100%
1.000000 2.250000 3.500000 5.250000 6.000000

``````test2 <- binning(test,4,method = "wtd.quantile",ordered = FALSE)
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
R

From novice to tech pro — start learning today.