[R] ifelse ?
Christian Schulz
ozric at web.de
Mon Dec 9 16:30:03 CET 2002
Hi,
i want transform data and using apply(data,2,fuz)
, but i don't know why the values < low & > high don't get 0 or 1, they
get
the value from Formula ,too "((x-low)/(high-low))" what's not the
intention ?
....is switch more approriate !?
thanks for advance ,Christian
fuz <- function (x) {
#x <- na.omit(x)
low <- quantile(x,0.15)[[1]]
high <- quantile(x,0.85)[[1]]
if (x < low ) zg <- 0
if (x >= low & x <= high)
zg <- ((x-low)/(high-low))
if (x > high)
zg <- 1
return(zg) }
fuz <- function (x) {
#x <- na.omit(x)
low <- quantile(x,0.15)[[1]]
high <- quantile(x,0.85)[[1]]
ifelse(x < low,0,(x-low)/(high-low))
ifelse (x > high,1,(x-low)/(high-low))}
More information about the R-help
mailing list