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

Patrick Connolly p.connolly at hortresearch.co.nz
Thu May 12 04:57:31 CEST 2005


On Thu, 12-May-2005 at 11:35AM +1000, Jones, Glen R wrote:

|> Hello,
|> 
|> Rather than rely on a set of IF statements (as there could be many -
|> please see below)), could the following be done in a different/better
|> way?
|> 
|> InternalMean <- mean(data1[,3])
|> 
|> if (InternalMean == 0)
|>     Intresult = 1
|> if (InternalMean > 0 & InternalMean < 1)
|>     Intresult = .95
|> if (InternalMean >= 1 & InternalMean < 2)
|>     Intresult = .85
|> if (InternalMean >= 2 & InternalMean < 4)
|>     Intresult = .70
|> ...
|> if (InternalMean >= 9)
|>     Intresult = .0

?switch

HTH

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~




More information about the R-help mailing list