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
     ❯   

统计 - 范围


范围是变异的度量,它描述了数据的分布情况。


范围

范围是数据中最小值和最大值之间的差值。

范围是最简单的变异度量。

以下是以截至2020年的所有934位诺贝尔奖获得者的年龄为基础绘制的直方图,显示了范围

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

最年轻的获奖者为17岁,最年长的为97岁。因此,诺贝尔奖获得者的年龄范围为80岁。


计算范围

范围只能针对数值数据进行计算。

首先,找出此示例中的最小值和最大值

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

通过从最大值中减去最小值来计算差值

72 - 13 = 59



使用编程计算范围

许多编程语言都可以轻松地找到范围。

对于大型数据集,使用软件和编程来计算统计数据更为常见,因为手动查找会变得很困难。

示例

使用 Python 的 NumPy 库 ptp() 方法来查找值 13, 21, 21, 40, 48, 55, 72 的范围

import numpy

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

x = numpy.ptp(values)

print(x)
自己尝试 »

示例

使用 R 的 min()max() 函数来查找值 13, 21, 21, 40, 48, 55, 72 的范围

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

max(values) - min(values)
自己尝试 »

注意: R 中的 range() 函数返回最小值和最大值。


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

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.