[R] "mystic" apply ?

Christian Schulz ozric at web.de
Tue Dec 10 21:03:02 CET 2002


hi,

have anybody a suggestion why this function
works only for a vector correct.
When i'm using apply(data,2,fuzzy) i have the columns
stacked (i.e. dim(x) =1000,4  should after the function 1000,8 
instead is 2000,4) - for single vector it's ok.


fuzzy  <- function (x) 
{
    fuz.x <- cbind(x, x)
    min <- quantile(x, 0.20)
    max <- quantile(x, 0.80)
    fuz.x[x >= max, 1] <- 1
    fuz.x[x >= max, 2] <- 0
    fuz.x[x <= min, 1] <- 0
    fuz.x[x <= min, 2] <- 1
    fuz.x[x > min & x < max, 1] <- (x[x > min & x < max] - min)/(max - min)
    fuz.x[x > min & x < max, 2] <- (max - x[x > min & x < max])/(max - min)
    fuz.x
}




More information about the R-help mailing list