[英]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.