[R] ELIF?

Johannes Graumann johannes_graumann at web.de
Thu Feb 15 09:40:18 CET 2007


Thanks for your help!

Joh

Duncan Murdoch wrote:

> On 2/14/2007 11:35 AM, Johannes Graumann wrote:
>> Hello,
>> 
>> Is there an elegant way to implement something like the elif function
>> (e.g. python) and prevent multiple if-else contruct concatenation when
>> coding in R?
> 
> Why not just concatenate, using "else if"?  For example,
> 
> if (condition1) {
>     action 1
> } else if (condition2) {
>     action 2
> } else if (condition3) {
>     action 3
> } else {
>     default action
> }
> 
> There is a switch() function if the condition is something that can be
> computed in advance, e.g. from the example on its man page:
> 
>   answer <- switch(type,
>               mean = mean(x),
>               median = median(x),
>               trimmed = mean(x, trim = .1))
> 
> ______________________________________________
> R-help at 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 and provide commented,
> minimal, self-contained, reproducible code.



More information about the R-help mailing list