Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output the most common value and the number of occurrences of that value in spreadsheet?

There is a column Values with a number of Strings, then show below the most common value and the number of occurrences of that value (i.e. mode of Strings). Here's an example.

+--------+
| Values |
+--------+
|   AA   |
+--------+
|   BB   |
+--------+
|   AA   |
+--------+
|   AA   |
+--------+
|   GG   |
+--------+
|   DD   |
+--------+
|   DD   |
+--------+
|        |
+-----------------+--------+
|   Most Common   |   AA   |
+-----------------+--------+
| Number of times |   03   |
+-----------------+--------+

This will be done in Google Spreadsheets! Any tips?

like image 502
ricardocaldeira Avatar asked Aug 06 '13 01:08

ricardocaldeira


People also ask

How do you find most common occurrences in Excel?

The most frequently occurring text refers to the maximum number of the repetitiveness of a particular text in a string. You can find it using the INDEX, MODE and MATCH functions. The generic function to find the most frequently occurring text is, =INDEX(range, MODE(MATCH(range, range, 0 ))).

How do you find the most common value in sheets?

In the Formulas Helper dialog box, do the following operations: Select Lookup option from the Formula Type drop down list; Then choose Find most common value from the Choose a fromula list box; In the right Arguments input section, select a list of cells that you want to extract the most common value beside the Range.

How do you find the most common number in a data set?

The mode of a data set is the number that occurs most frequently in the set. To easily find the mode, put the numbers in order from least to greatest and count how many times each number occurs. The number that occurs the most is the mode!

How do you get Excel to count occurrences of a value?

Count how often a single value occurs by using the COUNTIF function. Use the COUNTIF function to count how many times a particular value appears in a range of cells.


1 Answers

For your specific example, let that be column A, so you have A1='AA', A2='BB',...,A7='DD'.

To find the number of times the max element occurs, we want to count each unique element, then return the max count, so in a cell use the formula

=MAX(COUNTIF(A1:A7,A1:A7))

This is an ARRAY formula, so in excel you must hit Ctrl+Shift+Enter to use it. To use in google spreadsheets, surround it with ARRAYFORMULA so it becomes

=ARRAYFORMULA(MAX(COUNTIF(A1:A7,A1:A7)))

Explanation: the inside countif counts the cells of A1:A7, if they are equal to each value in A1:A7, and puts them in a list. Max returns the max value in that list.

Now, to get the actual element, we have another ARRAY formula. We can do an index/match lookup to figure out the value, so on the inside of the function, max finds the value with the greatest count, then that gets passed to an index+match function to find the value in the original list

=INDEX(A1:A7,MATCH(MAX(COUNTIF(A1:A7,A1:A7)),COUNTIF(A1:A7,A1:A7),0))

and so for google spreadsheets

=ARRAYFORMULA(INDEX(A1:A7,MATCH(MAX(COUNTIF(A1:A7,A1:A7)),COUNTIF(A1:A7,A1:A7),0)))

you replace each instance of A1:A7 with the actual range of your data.

This post was helpful: http://www.mrexcel.com/forum/excel-questions/34530-mode-text-strings.html

like image 96
chiliNUT Avatar answered Oct 13 '22 22:10

chiliNUT