Search
 
SCRIPT & CODE EXAMPLE
 

EXCEL

google sheets sort column by element frequency

# Basic syntax:
=SORT(A:A, COUNTIF(A:A, A:A), 0)
# Where:
#	- this will sort column A by the number of occurrences of each item
#		in column A
#	- COUNTIF($A:A, $A:A) only counts the occurrences of A1 in column A.
#		This is because COUNTIF is not an array formula. However, by
#		wrapping it inside the SORT function, that makes it behave as an
#		array formula, which causes it to return the count of each cell
#		in column A in column A
#	- SORT(A:A, ..., 0) sorts column A in descending order based on the
#		counts
# Note:
#	- if you want the unique occurrences of each item sorted by
#		frequency, wrap the sort function with UNIQUE()
#	- normally the second argument to SORT is the column number to sort
#		by, but it seems like if you provide an array of numbers of the
#		same length as the range, it uses those numbers first when
#		sorting, followed by any additional columns you specify
#	- the article this is based on uses IF(LEN(A:A), COUNTIF(...)). The
#		IF(LEN(A:A),,) part prevents the formula from including blank
#		cells, but isn't really necessary
Comment

PREVIOUS NEXT
Code Example
Excel :: excel conditionally highlight rows based on column 
Excel :: excel auto fit row height 
Excel :: excel paste into multiple columns 
Excel :: excel or formula 
Excel :: freeze row in excel 
Perl :: perl post condition 
Perl :: perl sprintf YYYYMMDD sample 
Perl :: Move files to new directory 
Perl :: what happened to perl 6 
Pascal :: pascal output 
Pascal :: pascal online compiler 
Powershell :: takeown command 
Powershell :: To look at a profile to see information about a wifi network 
Gdscript :: godot print enum name 
Abap :: adobre forms abap tcode 
Assembly :: docker cannot stop container 
Assembly :: vba check if shape name exists 
Assembly :: IPL_DEPTH_LABEL 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: week days array in javascrpt 
Javascript :: jquery redirect 
Javascript :: Javascript run code after page load 
Javascript :: react native reset cache 
Javascript :: moment get today, tomorrow, yesterday 
Javascript :: detect browser javascript 
Javascript :: javascript code to edit webpage 
Javascript :: react native rotate 
Javascript :: javascript loop through class elements 
Javascript :: js find object length 
Javascript :: javascript for loop over dictionary 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =