簡體   English   中英

R中的函數錯誤,二進制運算符的非數字參數

[英]Function Error in R, non-numeric argument to binary operator

我正在R中創建此函數,這將創建規范化。 data2YearlyIncome列的最小值與最大值之間有很大差異。 我想將值從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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM