Skip to content

ifelse ?

2 messages · Liaw, Andy, Christian Schulz

#
The following seems to do what you want:

fuz <- function(x) {
  x.range <- quantile(x, c(.15, .85))
  x[x < x.range[1]] <- x.range[1]
  x[x > x.range[2]] <- x.range[2]
  x <- (x - x.range[1]) / (x.range[2] - x)
  x
}

HTH,
Andy

-----Original Message-----
From: Christian Schulz [mailto:ozric at web.de]
Sent: Monday, December 09, 2002 10:23 AM
To: r-help at stat.math.ethz.ch
Subject: [R] ifelse ?


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))}

______________________________________________
R-help at stat.math.ethz.ch mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message.  If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.
#
many thanks !
Subscripting  is really the power of R and for next problems i hopefully
don't forget it :-(

christian


----- Original Message -----
From: "Liaw, Andy" <andy_liaw at merck.com>
To: "'Christian Schulz'" <ozric at web.de>; <r-help at stat.math.ethz.ch>
Sent: Monday, December 09, 2002 4:57 PM
Subject: RE: [R] ifelse ?
they
----
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named in this
message.  If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
============================================================================
==