[R] multiple selection syntax

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Sep 8 19:43:34 CEST 2003


anne wrote:

> Hello
> 
> This is a very newbie question on R syntax, but I do not find the 
> answer....
> 
> I want to make a selection on an interval say choose Xint in the 
> interval of temperatures 390-399
> 
> I tried this syntax
> Xint<- X[t>=390 && t< 400] typing >XintI get the answer numeric(0)
> 
> it did not select any object! 'though I verified that there indeed are 
> occrencies of X in this interval
> 
> 
> Any idea?
> 
> thanks
> 
> Anne

The idea is to read help("&&"). It tells you:

"& and && indicate logical AND and | and || indicate logical OR. The 
shorter form performs elementwise comparisons in much the same way as 
arithmetic operators. The longer form evaluates left to right examining 
only the first element of each vector. Evaluation proceeds only until 
the result is determined. The longer form is appropriate for programming 
control-flow and typically preferred in if clauses."

So I guess you want
  Xint <- X[(t >= 390) & (t < 400)]

Uwe Ligges




More information about the R-help mailing list