Skip to content
Back to formatted view

Raw Message

Message-ID: <4DD6F8B8782D584FABF50BF3A32B03D801A2BBC1@MSGBOSCLF2WIN.DMN1.FMR.COM>
Date: 2005-05-12T14:41:42Z
From: Brahm, David
Subject: Multiple IF statements - is there a better alternative?

Glen Jones <Glen.Jones at 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]

-- David Brahm (brahm at alum.mit.edu)