[英]Function Error in R, non-numeric argument to binary operator
我正在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)) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.