R中归一化后的NA
我有以下名为“天气”的数据帧,我正在尝试将其正常化:R中归一化后的NA,r,R,我有以下名为“天气”的数据帧,我正在尝试将其正常化: 'data.frame': 4745 obs. of 9 variables: $ TimeofDay : int 700 800 900 1000 1100 1200 1300 1400 1500 1600 ... $ AirTemp : num 16.4 17.7 19.3 19.8 21.3 ... $ Humidity : num 76.3 68.5 57.4 53.6 49.2 ... $
'data.frame': 4745 obs. of 9 variables:
$ TimeofDay : int 700 800 900 1000 1100 1200 1300 1400 1500 1600 ...
$ AirTemp : num 16.4 17.7 19.3 19.8 21.3 ...
$ Humidity : num 76.3 68.5 57.4 53.6 49.2 ...
$ Dewpoint : num 12.2 11.8 10.7 10.2 10.2 ...
$ BarPres : num 101 101 101 101 101 ...
$ MaxWindSpeed : num 4.45 5.25 5.25 6.85 5.25 ...
$ Zenith : num 99 88.4 81.7 72.2 64.5 59.2 57.1 58.4 63 70.3 ...
$ Azimuth : num -99 119 125 135 148 ...
$ TotalSolarRad: int 0 2 77 116 76 93 138 125 138 82 ...
我使用的标准规范化函数如下所示:
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x)))
}
函数将值更改为NA有什么原因吗?该函数可根据需要在其他数据帧上工作。
max()
,和min()
需要与na.rm=T
一起使用,以便在计算各自的结果时“跳过”na值 max()
和min()
需要与na.rm=T
一起使用,以便在计算各自的结果时“跳过”na值 这里的问题是向量包含NA值。对包含NA值的向量使用min()和max()返回NA。在min()和max()中有一个可选参数,即na.rm,默认设置为FALSE。
此参数设置为true时,允许min()和max()跳过NA值。因此,在这种情况下,将函数更改为
normalize <- function(x) {
return ((x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)))}
normalize这里的问题是向量包含NA值。对包含NA值的向量使用min()和max()返回NA。在min()和max()中有一个可选参数,即na.rm,默认设置为FALSE。
此参数设置为true时,允许min()和max()跳过NA值。因此,在这种情况下,将函数更改为
normalize <- function(x) {
return ((x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)))}
标准化请参见?max
。你想要na.rm
。发布一个可复制的示例,而不是str
。我也会这样做:r请参见?max
。您需要na.rm
。发布一个可复制的示例,而不是str
。我也会这样做:r那么我需要在哪里添加na.rm=T?那么我需要在哪里添加na.rm=T?
normalize <- function(x) {
return ((x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)))}