2 Replies Latest reply on Jan 22, 2016 5:56 AM by Batiste Roger

# How to create N classes with the same number of elements ?

Hi,

The histogram chart lets you create classes, but they don't have the same size. I'd like to split my variable in (for example) 5 groups, each group having the same number of observations.

Now because I couldn't figure out how to do it, I tried in R instead, and failed again. Here is the code, but maybe I don't even need code

SCRIPT_INT("require(Hmisc); Hmisc::cut2(.arg1, g = 5, levels.mean = T)", SUM([Var]))

Thanks you very much,

Cheers !

Note : if it helps, var has values from -12 to 2500, which are integers (-12 -11 ... 0 0 1 2 2 2 3 4 5 5 5 5 9 10 ... 2444 2488 2500)

• ###### 1. Re: How to create N classes with the same number of elements ?

Hi Batiste,

I created evenly sized bins using an IF THEN statement that compares the index value of a number to total number of items. The following instructions will create a histogram of [Sales] in the sample data set Superstore with evenly sized bins:

1. Create a calculated field with a name like "Bin Size" with a calculation similar to the following:

WINDOW_SUM( COUNT( [Sales] ))
/
10
2. Create a calculated field with a name like "Evenly sized bins" with a calculation similar to the following:

IF INDEX() < [Bin Size]
THEN "Group 1"
ELSEIF INDEX() < [Bin Size] * 2
THEN "Group 2"
ELSEIF INDEX() < [Bin Size] * 3
THEN "Group 3"
ELSEIF INDEX() < [Bin Size] * 4
THEN "Group 4"
ELSEIF INDEX() < [Bin Size] * 5
THEN "Group 5"
ELSEIF INDEX() < [Bin Size] * 6
THEN "Group 6"
ELSEIF INDEX() < [Bin Size] * 7
THEN "Group 7"
ELSEIF INDEX() < [Bin Size] * 8
THEN "Group 8"
ELSEIF INDEX() < [Bin Size] * 9
THEN "Group 9"
ELSE "Group 10"
END

3. Drag [Evenly Sized Bins] to the Columns shelf
4. Drag [Sales] to the Rows shelf
5. Right-click on Sales on the Rows shelf and select Measure > Count
6. In the Analysis menu, uncheck Aggregate Marks

1 of 1 people found this helpful
• ###### 2. Re: How to create N classes with the same number of elements ?

Awesome !

Still a bit more complex than it should (I'm sure it will ship in a future version), but completely fine.