RE: [R] Multiple IF statements - is there a better alternative?

From: Brahm, David <David.Brahm_at_geodecapital.com>
Date: Fri 13 May 2005 - 00:41:42 EST


Glen Jones <Glen.Jones@team.telstra.com> wrote:
> if (InternalMean == 0)
> Intresult = 1
> if (InternalMean > 0 & InternalMean < 1)
> Intresult = .95
> [etc.]

This looks like a job for "cut":

R> i <- cut(InternalMean, c(-Inf,0,1,2,4,9,Inf), labels=F) R> Intresult <- c(1,.95,.85,.70,.50,0)[i]


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 13 00:45:55 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:44 EST