Brutish calculation of nth mode

CaptainPi

New Member
Joined
Aug 15, 2012
Messages
4
Hello,I'm trying to calculate the "nth mode" (i.e. the nth most frequent value) in a large list. Alternatively, I want to rank the values of the list from most frequently appearing to least frequently appearing.A brutish way that I thought of doing this would be to calculate the mode then delete all instances of the mode in the list, calculate the mode of the new list (thereby giving me the second most frequent element), and repeating this process until the list is empty. How would I do this using a macro?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
hi,

What about instead using a pivot table? Make a pivot table with the values as a row field and also a data field - the data field being a count. Then sort the row field on descending counts. now you have a list with the most frequent at the top and its count adjacent. For the nth value, use an INDEX formula.

HTH
 
Upvote 0
hi,

What about instead using a pivot table? Make a pivot table with the values as a row field and also a data field - the data field being a count. Then sort the row field on descending counts. now you have a list with the most frequent at the top and its count adjacent. For the nth value, use an INDEX formula.

HTH

Hi, thank you for your reply. I'm unfamiliar with pivot tables. Can you walk me through what you just said. (I'm using Excel 2010.)
 
Upvote 0
Here is a link to some well presented info DataPig Technologies

And also Contextures Excel Tips, Excel Tutorials and Excel Examples

Pivot tables have been around since the mid 1990s. Please google, or refer to Excel help, you'll find lots more info. They are wonderful tools. Row fields are on the left hand side, data fields in the middle. A numeric data field will default to SUM but for your task needs to be changed to COUNT. I work in Excel 2003 & right clicking from a pivot table item is often a means to change properties & settings - I don't know about Excel 2010 though.

regards
 
Last edited:
Upvote 0
Hello,I'm trying to calculate the "nth mode" (i.e. the nth most frequent value) in a large list. Alternatively, I want to rank the values of the list from most frequently appearing to least frequently appearing.A brutish way that I thought of doing this would be to calculate the mode then delete all instances of the mode in the list, calculate the mode of the new list (thereby giving me the second most frequent element), and repeating this process until the list is empty. How would I do this using a macro?
Here's a formula method.

Book1
AB
1ValueHeader
216
3110
421
533
634
74_
84_
95_
106_
116_
126_
1310_
1410_
1510_
Sheet1

I'm using Excel 2010
This array formula** entered in B2:

=IFERROR(MODE(IF(ISNA(MATCH(A$2:A$15,B$1:B1,0)),A$2:A$15)),"")

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Copy down until you get blanks.
 
Upvote 0
Hi, unfortunately the list is very long (million rows) and that technique seems too computationally intensive (for the first 500 rows it took about 5 minutes). For some reason the pivot table works it out very quickly.
 
Upvote 0
Hi, unfortunately the list is very long (million rows) and that technique seems too computationally intensive (for the first 500 rows it took about 5 minutes). For some reason the pivot table works it out very quickly.
Yeah, that would take a while to calculate on 1m rows of data!
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top