rstudio中位数的公式

In this tutorial, let’s learn how we can find the median in R. Median is defined as the measurement of central tendency in the data. In simpler terms, you may call it the ‘middle’ value.

在本教程中,让我们学习如何在R中找到中位数。中位数定义为数据中中心趋势的度量。 简单来说,您可以将其称为“中间”值。

The process includes grouping or ordering the values and then finding the middle number among them. If you encounter multiple middle values, you can take the average or ‘mean’ of those values.

该过程包括对值进行分组或排序,然后在其中找到中间的数字。 如果遇到多个中间值,则可以取这些值的平均值或“平均值”



中位数–优缺点 (Median – Merits and Demerits )

Merits:

优点:

  • It is very easy to calculate the median. In some simple cases, you can find the median just by analyzing the values.计算中位数非常容易。 在一些简单的情况下,您可以仅通过分析值来找到中位数。
  • Median has real use in open-ended data distributions. Because the median gives more importance to the position of the number than its value.中位数在开放式数据分发中有实际用途。 因为中位数比数字的值更重视数字的位置。
  • One of the major advantages of the median is that it is not affected by the outliers present in the data.中位数的主要优势之一是它不受数据中存在的异常值的影响。

Outliers: Outliers are described as the extreme values, which are different from the rest of the values in the data.

离群值:离群值描述为极值,与数据中的其余值不同。

Ex: The retirement age values are – (52,53,54,54,55,56,57,58,79)

例如:退休年龄值为–(52,53,54,54,55,56,57,58,79)

Here, 79 is an extreme value and it is different from the rest of the values or data. It will affect the mean and mode drastically. But Median will not be affected as it deals with position rather than the value.

在这里,79是一个极值,它不同于其余的值或数据。 它将严重影响均值和众数。 但是中位数不会受到影响,因为它只处理头寸而不是价值。

Demerits:

缺点:

  • Median will not look for the accurate value as it will not utilize the entire data.中位数不会寻找 准确的价值,因为它不会利用全部数据。
  • Median is not capable of further statistical or mathematical operations.中位数不能进行进一步的统计或数学运算。


查找给定值的中位数 (Finding the median of the given values)

In this section, we will create a list of values and try to find the median of those values.

在本节中,我们将创建一个值列表,并尝试查找这些值的中位数。


#creates a list
x <- c(45,76,56,87,65,45,34,56,78,98,87,65,34,48,76)  #displays the values
show(x)
---> 45 76 56 87 65 45 34 56 78 98 87 65 34 48 76#calculates the median of the values in the list 'x'
median(x)

Output: 65

输出:65

You may wonder how 65 can be a middle value. Well, the median() function first groups or order the values in ascending or descending order, then it will calculate the middle or central value.

您可能想知道65如何成为中间值。 好吧,位数()函数首先将值分组或以升序或降序排列,然后将计算中间值或中心值。

Note: If one or more values are found to be central values, then the average of them will be considered as the median.

注意:如果发现一个或多个值是中心值,则将它们平均值视为中位数



查找“国家的用电量数据”的中位数。 (Finding the median of the ‘Electricity consumption data of the countries’.)

In this section, we import the CSV file which includes the data of ‘Electricity/energy consumption’ across the above-mentioned countries – India, Romania, USA, and Jamaica in the year 2019.

在本部分中,我们导入CSV文件 ,其中包含上述国家(印度,罗马尼亚,美国和牙买加)在2019年的“电力/能源消耗”数据。

Execute the below code to find the median of the ‘Voltage’ consumed by these countries in 2019.

执行以下代码以查找这些国家/地区在2019年所消耗的“电压”中位数。

Note: View or Download the ‘Energy consumtion’ dataset here

注意: 在此处查看或下载“能源消耗”数据集


#reads the value present in the file.
df <- read.csv("energydata.csv")#displays the values.
df#calculates the median of the 'voltage' values.
median(df$Voltage)

Output: 220 Volts,

输出:220

Note: In this data set, the results showed that the median is 220, i.e. the central tendency of the data is 220 volts.

注意:在此数据集中,结果显示中位数为220,即数据的中心趋势为220伏。



借助箱形图可视化数据的中位数 (Visualizing the Median of the data with the help of the box plot)

In R, you can create a box plot to understand the distribution of median as shown in the below plot.

在R中,您可以创建一个箱形图以了解中位数的分布,如下图所示。

boxplot: Boxplots are used in R to understand the distribution of data. R offers the function boxplot() to create the box graph. The thick line in the plot represents the median.

boxplot R中使用Boxplots来了解数据的分布。 R提供了boxplot()函数来创建箱形图。 图中的粗线代表中位数。



使用直方图了解“电压”的中值 (Using Histogram to Understand the Median of the ‘voltage’)

In this section, we are going to plot the voltage distribution with the help of a histogram in Rstudio.

在本节中,我们将借助Rstudio中的直方图来绘制电压分布

Execute the below code to plot the histogram, which shows the voltage distribution and the median of the voltage.

执行以下代码以绘制直方图,该直方图显示电压分布和电压中值。


#reads the value present in the file.
df <- read.csv("energydata.csv")
#displays the values.
df
#calculates the median of the 'voltage' values.
median(df$Voltage)
#plots the histogram
hist(df$Voltage, col='orange', xlab='voltage', ylab='frequency', main='Voltage distribution')
#adds the median line
abline(v=median(df$Voltage), col='black', lwd='3')
#adds the legend
legend(x='topright', c('median'),col = 'black', lwd = '3')

In the above plot, you can see the ‘black’ line, which is actually showing the median. Through the histograms we can easily demonstrate the mean, median, and density curves as well.

在上图中,您可以看到“黑”线,它实际上是显示中位数。 通过直方图,我们还可以轻松显示均值,中值和密度曲线。

结论 (Conclusion)

With the help of the Median() function, we can understand the central tendency of the data. Median is very easy to find in some cases, where you are able to tell the median value by just inspecting it.

借助Median()函数,我们可以了解数据的集中趋势。 在某些情况下,很容易找到中值,您可以通过检查中值来判断中值。

R offers great visualizing functions to understand the hidden data patterns. As shown above, you can easily analyze the median using the histogram and box plots.

R提供了出色的可视化功能,以了解隐藏的数据模式。 如上所示,您可以使用直方图和箱形图轻松分析中位数

That’s all for now. Connect with us for more R tutorials. Don’t hesitate to comment below if you have any queries. Happy learning!!!.

目前为止就这样了。 与我们联系以获取更多R教程。 如有任何疑问,请在下面评论。 学习愉快!

翻译自: https://www.journaldev.com/39066/find-the-median-in-r

rstudio中位数的公式

rstudio中位数的公式_如何在R中找到中位数相关推荐

  1. r求矩阵某一列的标准偏差_如何在R中找到标准偏差?

    r求矩阵某一列的标准偏差 Being a statistical language, R offers standard function sd(' ') to find the standard d ...

  2. 股票beta值的均值_如何在R中找到值的均值

    股票beta值的均值 In statistics, mean is defined as the 'average' value that you get when you add all the v ...

  3. 如何在 R 中找到 F 临界值

    当您进行 F 检验时,您将获得 F 统计量作为结果.要确定 F 检验的结果是否具有统计显着性,可以将 F 统计量与 F 临界值进行比较.如果 F 统计量大于 F 临界值,则检验结果具有统计显着性. F ...

  4. rstudio r语言_如何在R中接受用户输入?

    rstudio r语言 Taking a user input is very simple in R using readline() function. In this tutorial, we ...

  5. csv文件示例_如何在R中使用数据框和CSV文件-带有示例的详细介绍

    csv文件示例 Welcome! If you want to start diving into data science and statistics, then data frames, CSV ...

  6. 不用sqrt实现平方根_如何在R中使用sqrt()查找平方根?

    不用sqrt实现平方根 Getting a square root of the values in R is easy with the function sqrt() in R. Let's fi ...

  7. r语言min-max归一化_如何在R中使用min()和max()

    r语言min-max归一化 Finding min and max values is pretty much simple with the functions min() and max() in ...

  8. python 运行r语言_如何在R中运行Python

    python 运行r语言 尽管我很喜欢R,但很显然Python还是一种很棒的语言-既适用于数据科学又适用于通用计算. R用户想要在Python中做一些事情可能有充分的理由. 也许这是一个很棒的库,还没 ...

  9. mysql中转换成字符串_如何在R中转换字符串的大小写?

    mysql中转换成字符串 Hello, folks. In this tutorial we are going to convert the case of the string in R. The ...

最新文章

  1. 阅读Book: MultiObjective using Evolutionary Algorithms (3) -----关于pareto最优的各种概念
  2. jboss架构_检查Red Hat JBoss BRMS部署架构的规则和事件(第一部分)
  3. 真格量化——GFTD策略
  4. 我要成为一名优秀的程序员!
  5. mysql 重置自增长_怎么重置mysql的自增列AUTO_INCREMENT初时值
  6. GCC编译优化指南【作者:金步国】
  7. JSP的自定义标签(五)之Tag File
  8. Linux程序包管理和yum用法
  9. 高可用架构系列之京东亿级商品详情页架构演进技术解密
  10. (8)USB协议 —— 高速模式握手过程
  11. linux下输入法终极解决方案
  12. 动态物体检测(python)
  13. 英语流利说 第39天
  14. leetcode 咒语和药水的成功对数
  15. 用什么软件编写html语言,可以用什么工具编写javascript?
  16. Gateway原理及实例
  17. 英语preciouscorals贵珊瑚PreciousCorals红珊瑚
  18. 需求调研前的准备工作
  19. 勾股定理 —— 证明大全
  20. 【初探篇】申请阿里云免费SSL证书并配置https访问实战

热门文章

  1. echarts 饼状图 扇面上显示 文字和百分比
  2. 快速排序——Java代码实现
  3. python 简历解析初探 (NLP)
  4. 安卓_第三方QQ授权登录
  5. 【BUG:unable to connect redis 6379】
  6. 计算机接口统称,石油华东《计算机接口技术》2016年秋学期在线作业一二三答案...
  7. html如何调节透明度,CSS 如何设置一个元素的透明度呢?
  8. java零基础 笔记总结【适合初学者】
  9. 全景照片做成html,全景嵌入HTML页面插件
  10. 2022年山东省安全员C证考试题模拟考试题库及在线模拟考试