[R] Multiple IF statements - is there a better alternative?
Brahm, David
David.Brahm at geodecapital.com
Thu May 12 16:41:42 CEST 2005
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)
More information about the R-help
mailing list