[R] Odp: if statement
Petr PIKAL
petr.pikal at precheza.cz
Mon Jan 5 12:57:12 CET 2009
Hi
r-help-bounces at r-project.org napsal dne 05.01.2009 12:41:49:
>
> Hi,
>
> How do I check for two conditions in an if loop? I want to check if a
value
> lies between 2 other values.
>
> For example,
>
> A <- ts(rnorm(120), freq=12, start=c(1992,8))
> X <- 0.5
> Y <- 0.8
>
> I would like to create a new vector C for which C[i] is 0 if A[i] lies
in
> between X and Y.
Well, you do not say what you want for C values if A[i] is not in such
interval. So
C<-(A<X|A>Y)*1
gives you zeros in required positions and ones in other positions.
Regards
Petr
>
> Would be grateful for any help. Sorry for asking such an R-newbie
question!
>
> Shruthi
> --
> View this message in context: http://www.nabble.com/if-statement-
> tp21289608p21289608.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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