[R] how to skip part of the code

PIKAL Petr petr.pikal at precheza.cz
Wed Mar 20 14:21:44 CET 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Andras Farkas
> Sent: Wednesday, March 20, 2013 2:11 PM
> To: r-help at r-project.org
> Subject: [R] how to skip part of the code
> 
> Dear All,
> 
> another quick question, this one is on skipping part of my code, so let
> us say:
> 
> a <-5
> b <-2
> e <-0
> 
> d <-a+b
> f <-a-b
> 
> what I would like to do is to have R NOT to calculate the value for d
> in case the value of e equals to zero (essentially skip that "chunk"),
> but instead move on to calculate te value for f. In the code I am
> working with the value of e changes, and I would like to calculate d
> and f at all times when the value of e is greater then zero. If
> possible, I would like to do this without using the functions "ifelse"
> and "if else"

Why? This is exactly the reason for which if else was invented?

I am not sure if some simple solution without if is available.

if (e > 0) { d <- a+b; f <- a-b }

seems to be simple.

Regards
Petr

> 
> appreciate the help,
> 
> Andras
> 	[[alternative HTML version deleted]]



More information about the R-help mailing list