r语言min-max归一化

Finding min and max values is pretty much simple with the functions min() and max() in R.

使用R中的min()max()函数,可以找到最小值和最大值。

You know that we have functions like mean, median, sd, and mode to calculate the average, middle, and dispersion of values respectively. But did you ever thought of a function which gives you min and max values in a vector or a data frame?

你知道,我们有这样的功能平均值 , 中位数 , SD和模式分别计算平均值,中间和值的波动。 但是您是否想到过一个可以在向量或数据帧中为您提供最小值和最大值的函数?

If so, congratulations, you have got functions named min() and max() which returns the minimum and maximum values respectively.

如果是这样,那么恭喜您,您获得了名为min()max()的函数,它们分别返回最小值和最大值。

Sounds interesting right? Let’s see how it works!

听起来很有趣吧? 让我们看看它是如何工作的!



让我们从语法开始 (Let’s start with the syntax)

The syntax of the min() function is given below.

min()函数的语法如下。


min(x, na.rm = FALSE)
  • x = vector or a data frame.x =向量或数据帧。
  • na.rm = remove NA values, if it mentioned False it considers NA or if it mentioned True it removes NA from the vector or a data frame.na.rm =删除NA值,如果提到False,则认为NA;如果提到True,则从向量或数据帧中删除NA。

The syntax of the max() function is given below.

max()函数的语法如下。


max(x, na.rm = FALSE)
  • x = vector or a data frame.x =向量或数据帧。
  • na.rm = remove NA values, if it mentioned False it considers NA or if it mentioned True it removes NA from the vector or a data frame.na.rm =删除NA值,如果提到False,则认为NA;如果提到True,则从向量或数据帧中删除NA。


R中的Max()函数 (Max() function in R)

In this section, we are going to find the max values present in the vector. For this, we first create a vector and then apply the max() function, which returns the max value in the vector.

在本节中,我们将找到向量中存在的最大值。 为此,我们首先创建一个向量,然后应用max()函数,该函数返回向量中的最大值。


#creates a vector
vector<-c(45.6,78.8,65.0,78.9,456.7,345.89,87.6,988.3)#returns the max values present in the vector
max(vector)

Output= 988.3

输出= 988.3



R中的Min()函数 (Min() function in R)

Here, we are going to find the minimum value in a vector using function min(). You can create a vector and then apply min() to the vector which returns the minimum value as shown below.

在这里,我们将使用min()函数在向量中找到最小值。 您可以创建一个向量,然后将min()应用于该向量,该向量将返回最小值,如下所示。


#creates a vector
vector<-c(45.6,78.8,65.0,78.9,456.7,345.89,87.6,988.3)#returns the minimum value present in the vector
min(vector)

Output = 45.6

输出= 45.6



R中具有NA值的Max()函数 (Max() function in R with NA values)

Sometimes in the data analysis, you may encounter the NA values in a data frame as well as a vector. Then you need to bypass the NA values in order to get the desired result.

有时在数据分析中,您可能会在数据帧和向量中遇到NA值。 然后,您需要绕过NA值以获得所需的结果。

The max function won’t return any values if it encounters the NA values in the process. Hence you have to remove NA values from the vector or a data frame to get the max value.

如果max函数在过程中遇到NA值,则不会返回任何值。 因此,您必须从向量或数据帧中删除NA值才能获得最大值


#creates a vector having NA values
df<- c(134,555,NA,567,876,543,NA,456)#max function won't return any value because of the presence of NA.
max(df)#results in NA instead of max value
Output = NA

So to avoid this and get the max value we are using na.rm function to remove NA values from the vector. Now you can see that the max() function is returning the maximum value.

因此,为了避免这种情况并获得最大值,我们使用na.rm函数从向量中删除NA值。 现在您可以看到max()函数正在返回最大值。


#max function with remove NA values is set as TRUE.
max(df, na.rm = T)

Output = 876

输出= 876



R中具有NA值的Min()函数 (Min() function in R with NA values)

Just like we applied the max function in the above section, here we are going to find the minimum value in a vector having NA values.

就像我们在上一节中应用max函数一样,这里我们将在具有NA值的向量中找到最小值。


#creates a vector having NA values
df<- c(134,555,NA,567,876,543,NA,456)#returns NA instead of minimum value
min(df)

Output = NA

输出= NA

To overcome this, we are using na.rm function to remove NA values from the vector. Now you can that the min() function is returning the min value.

为了克服这个问题,我们使用na.rm函数从向量中删除NA值。 现在您可以使min()函数返回最小值。


#creates a vector having NA values
df<- c(134,555,NA,567,876,543,NA,456)#removes NA values and returns the minimum value in the vector
min(df, na.rm = T)

Output = 134

输出= 134



字符向量中的Min()和Max()函数 (Min() and Max() functions in a character vector)

Till now we have dealt with numerical minimum and maximum values. If I have to tell you something, I wish to say that you can also find the min and max values for a character vector as well. Yes, you heard it right!

到现在为止,我们已经处理了数值的最小值和最大值。 如果需要告诉您一些信息,我想说的是,您也可以找到字符向量的最小值和最大值。 是的,您没听错!

Let’s see how it works!

让我们看看它是如何工作的!

In the case of character vectors, the min and max functions will consider alphabetical order and returns min and max values accordingly as shown below.

对于字符向量,min和max函数将考虑字母顺序,并相应地返回min和max值,如下所示。


#creates a character vector with some names
character_vector<- c('John','Angelina','Smuts','Garena','Lucifer')#returns the max value
max(character_vector)

Output = “Smuts”

输出=“黑穗病”

Similarly, we can find the minimum values in the character vector as well using min() function which is shown below.

同样,我们也可以使用min()函数在字符向量中找到最小值,如下所示。


#creates a character vector with some names
character_vector<- c('John','Angelina','Smuts','Garena','Lucifer')#returns the minimum values in the vector
min(character_vector)

Output = “Angelina”

输出=“天使”



数据帧中的Min()和Max()函数 (Min() and Max() functions in a data frame )

Let’s find the minimum and maximum values of a data frame by importing it. The min and max values in a dataset will give a fair idea about the data distribution.

通过导入来查找数据帧的最小值和最大值。 数据集中的最小值和最大值将为数据分配提供一个合理的思路。

This is the air quality dataset that is available in R studio. Note that the dataset includes NA values. With the knowledge of removing NA values using na.rm function, let’s find the min and max values in the Ozone values.

这是R studio中可用的空气质量数据集。 请注意,数据集包含NA值。 了解使用na.rm函数删除NA值后,让我们在Ozone值中找到最小值和最大值。


min(airquality$Ozone, na.rm=T)

Output = 1

输出= 1


max(airquality$Ozone, na.rm = T)

Output = 168

输出= 168

Let’s find the min and max values of the Temperature values in the airquality dataset.

让我们在空气质量数据集中找到温度值的最小值和最大值。

min(airquality$Temp, na.rm = T)

Output = 56

输出= 56


max(airquality$Temp, na.rm = T)

Output = 97

输出= 97



结语 (Wrapping up)

Well, in this tutorial we have focussed on finding the minimum and maximum values in a vector, data frame, and a character vector as well.

嗯,在本教程中,我们集中于查找向量,数据帧和字符向量中的最小值和最大值。

The min and max functions can be used in both numerical as well as character vectors. You can also remove the NA values using na.rm function to get better accuracy and desired results.

最小值和最大值函数可用于数值向量和字符向量。 您也可以使用na.rm函数删除NA值,以获得更好的准确性和所需的结果。

That’s all for now. I hope you will find more min and max values as shown in the above sections. Don’t forget to hit the comments section for any queries.

目前为止就这样了。 我希望您会发现更多的最小值和最大值,如以上各节所示。 不要忘记点击注释部分进行任何查询。

Happy learning!!!

学习愉快!

More study: R documentation

更多研究: R文档

翻译自: https://www.journaldev.com/40266/min-max-in-r

r语言min-max归一化

r语言min-max归一化_如何在R中使用min()和max()相关推荐

  1. r语言msar如何用_如何在jupyter notebook中使用R语言

    前人之述备矣,然则操作系统不同,软件版本相异,软件安装途径有别,只为于jupyter中使用R,所遇之难 ,得无异乎? 问题陈述 操作系统:win10 64 软件叙述:安装了anaconda, R(不是 ...

  2. r语言 林元震_科学网—R语言简介 - 林元震的博文

    R既是软件,也是语言,在GNU协议General Public Licence下免费发行,是1995年由新西兰奥克兰大学统计系的Ross Ihaka和Robert Gentleman基于S语言基础上共 ...

  3. r语言remarkdown展示图_为什么Markdown R有较大概率成为科技写作主流? ← 阳志平的个人网站::技术...

    为什么Markdown+R有较大概率成为科技写作主流? 废话 上周五,我对友人说,十年后,基于Markdown+R的科技写作方式将有较大概率成为主流.而这一切,少不了来自一位友人的重要开源贡献.他给这 ...

  4. r语言 柱状图加星号_如何用R画分组柱状图并且添加标准差和显著性标记(星号)?...

    时间过了这么久,该交一份答案了.ggplot2包 是一个图形可视化包,并不带统计分析功能,所以统计学分析需要另外去做. 这里加bar和显著性标识,如果了解ggplot2绘图原理中的图层概念的话,就能明 ...

  5. r dataframe 转成向量_快速掌握R语言中类SQL数据库操作技巧

    在数据分析中,往往会遇到各种复杂的数据处理操作:分组.排序.过滤.转置.填充.移动.合并.分裂.去重.找重.填充等操作.这时候R语言就是一个很好的选择:R可以高效地.优雅地解决数据处理操作.(本章节为 ...

  6. r语言library什么意思_医学统计与R语言:百分条图与雷达图

    微信公众号:医学统计与R语言如果你觉得对你有帮助,欢迎转发 百分条图-输入1: library(ggplot2) 结果1: year 输入2: percentbar <- gather(perc ...

  7. r语言boxcox异方差_基于R语言进行Box-Cox变换

    原标题:基于R语言进行Box-Cox变换 作者简介 作者:吴健中国科学院大学 R语言.统计学爱好者,尤其擅长R语言和Arcgis在生态领域的应用分享 个人公众号:统计与编程语言 Q: 为什么要进行Bo ...

  8. r语言java环境安装_【R语言入门】R语言环境搭建

    说明 R 语言是一个功能十分强大的工具,几乎绝大多数的数据分析工作都可以在 R 中完成,并且拥有很极强的绘图功能支持,能让你手中的数据以各种姿势进行可视化呈现,而且支持 Windows.Mac OS. ...

  9. r语言 林元震_方差分析--T检验和F检验的异同

    方差分析--T检验和F检验的异同 最近在图书馆借了本<R和ASReml-R统计分析教程>,林元震和陈晓阳主编的关于R的书籍,当时看上这本书的原因在于里面以统计学知识为主,作为R语言实战的良 ...

最新文章

  1. Photoshop抠图、污点处理等常用功能及快捷键
  2. layer.js 弹窗组件API文档
  3. 16.PHP_Ajax模拟服务器登录验证
  4. 华三交换机mode是什么意思_POE交换机150米、长距离250米传输是什么意思?
  5. centos7 安装java和tomcat9
  6. 负载敏感系统详解_宣布Enarx用于运行敏感工作负载
  7. phalapi 数据库锁_phalApi数据库操作
  8. 堡垒机应用发布服务器是干嘛的_支持Web UI数据库审计和敏感数据国密算法加密,JumpServer堡垒机v2.5.0发布丨Release Notes...
  9. python编程入门指南-Python 入门指南
  10. echarts x轴坐标文字显示不全
  11. 520超浪漫文艺表白,追求女神必备!!动态Html网页,无编程基础也可娱乐
  12. 基于微信小程序点餐系统的设计与实现
  13. matlab 平滑曲线连接_曲线拟合的一些想法
  14. memory repair
  15. windows磁盘管理压缩卷只能压缩一部分的问题解决办法
  16. 海康摄像头之FTP服务器搭建及使用
  17. 网站安全漏洞--大全
  18. css实现icon动画效果
  19. Meta AI:让手绘小人动起来
  20. 服务端技术方案模板参考

热门文章

  1. 微信 input 照相机 呼出
  2. javascript--Date
  3. js 数组对象的操作方法
  4. php -- 目录、路径、磁盘
  5. jQuery获取隐藏文本域
  6. [转载] python staticmethod有什么意义_Python 中的 classmethod 和 staticmethod 有什么具体用途
  7. [转载] numpy.take()从数组中取指定的行或列
  8. Jmeter中java接口测试
  9. java-成员变量的属性与成员函数的覆盖
  10. 检测邮箱和手机号是否正确的正则