Here's the answer from the 2nd question you link:
function(x) {(x - min(x)) / (max(x) - min(x))}
We can modify this to work with NAs (using the built-in NA handling in min
and max
stdize = function(x, ...) {(x - min(x, ...)) / (max(x, ...) - min(x, ...))}
Then you can call it and pass through na.rm = T
.
x = rexp(100)
x[sample(1:100, size = 10)] <- NA
stdize(x) # lots of NA
stdize(x, na.rm = T) # works!
Or, using the o
data frame from your question:
o_std = lapply(o, stdize, na.rm = T)
The NA
s will still be there at the end.