我已经看到了这些解决方案:
但是,如果存在NA值,该方法将无法工作。
我尝试了这个:
s = append(sort(rexp(100)),rep(NA,30))
o = data.frame(s,s)
range01 <- function(x){
if (!is.na(x))
{
return(NA)
}
else{
y = (x-min(x))/(max(x)-min(x))
return(y)}
}
xo = apply(o,MARGIN = 2, FUN = range01)
Run Code Online (Sandbox Code Playgroud)
但这不起作用...建议吗?
该解决方案应通过apply函数在数据框上工作
r ×1