I received a lot of good advice how to remove NaN columns - thank you all 
!!!
The simplest mechanism to center/scale and remove NaN columns seems to be

> xdata <- data.frame(A = 3:1, B = 1:3, rep(9, 3))
> xs <- scale(xdata)
> mask <- sapply(as.data.frame(xs), function(x) all(is.nan(x)))
> scaled.centered.x <- as.data.frame(xs)[!mask]
> scaled.centered.x
   A  B
1  1 -1
2  0  0
3 -1  1

Note that as.data.frame(xs) is important, because apparently xs from 
scale() function
is not a data frame and if as.data.frame() is omitted in the code fragment 
above we get something like this

> mask <- sapply(xs,  function(x) all(is.nan(x)))
> xs[!mask]
   1    2    3 <NA> <NA> <NA>
   1    0   -1   -1    0    1
 

Maybe somebody more knowledgeable could give some explanation for this 
behavior.

Ryszard
        [[alternative HTML version deleted]]

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to