Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Statistics - Range


The range is a measure of variation, which describes how spread out the data is.


Range

The range is the difference between the smallest and the largest value of the data.

Range is the simplest measure of variation.

Here is a histogram of the age of all 934 Nobel Prize winners up to the year 2020, showing the range:

Histogram of the age of Nobel Prize winners with range shown between the minimum and maximum values.

The youngest winner was 17 years and the oldest was 97 years. The range of ages for Nobel Prize winners is then 80 years.


Calculating the Range

The range can only be calculated for numerical data.

First, find the smallest and largest values of this example:

13, 21, 21, 40, 48, 55, 72

Calculate the difference by subtracting the smallest from the largest:

72 - 13 = 59



Calculating the Range with Programming

The range can easily be found with many programming languages.

Using software and programming to calculate statistics is more common for bigger sets of data, as finding it manually becomes difficult.

Example

With Python use the NumPy library ptp() method to find the range of the values 13, 21, 21, 40, 48, 55, 72:

import numpy

values = [13,21,21,40,48,55,72]

x = numpy.ptp(values)

print(x)
Try it Yourself »

Example

Use the R min() and max() functions to find the range of the values 13, 21, 21, 40, 48, 55, 72:

values <- c(13,21,21,40,48,55,72)

max(values) - min(values)
Try it Yourself »

Note: The range() function in R returns the smallest and largest values.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.