我实际上正在处理一个数据集中的离群值。所以我需要帮助。
我在互联网上找到了这段代码。但是真的不明白它是如何工作的吗?
out_std = function(x){
m = mean(x)
s = sd(x)
lc = m-3*s
uc= m+3*s
n = sum(x>uc | x<lc )
val = list(num=n,lower_cutoff=lc,upper_cutoff=uc)
return(val)
lc=out_std(cr_data1$CoapplicantIncome)$lower_cutoff
uc=out_std(cr_data1$CoapplicantIncome)$upper_cutoff
cr_data1$CoapplicantIncome[cr_data1$CoapplicantIncome>uc]=uc
cr_data1$CoapplicantIncome[cr_data1$CoapplicantIncome<lc]=lc
```r
There's nothing wrong in Output part.