我正在R中创建此函数,这将创建规范化。在中data2
,YearlyIncome
列从最小值到最大值有很大差异。我想归一化将值从0转换为1。
apply函数的值将覆盖YearlyIncome
。
> x <- data2$YearlyIncome
> a <- min(x)
> b <- max(x)
> fun <- function(x){ (x - a) / (b - a) }
> fun(data$YearlyIncome)
Error in data$YearlyIncome : object of type 'closure' is not subsettable
> fun <- function(x){ (x - min(x))/(max(x) - min(x)) }
> fun(data2[1])
Show Traceback
Rerun with Debug
Error in FUN(X[[i]], ...) :
only defined on a data frame with all numeric variables
But I got this error:
>Error in x - a : non-numeric argument to binary operator
那我现在该怎么办?
在这里,我们将第一列设置为子集。在apply
不需要为该。
fun(data$YearlyIncome)
在哪里
fun <- function(x){ (x - min(x))/(max(x) - min(x)) }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句