0
x = seq(-0.5, 0.5, 0.1)

Why does

x > 0
[1] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE

take every value of the sequence while

x > 0 && x < 5
[1] FALSE

takes only the first value?

IRTFM
  • 258,963
  • 21
  • 364
  • 487
Kiwi
  • 73
  • 7
  • 3
    Those are different operators. Type `help("&&")` for more info on the difference – talat Nov 04 '14 at 20:45
  • Thanks! ? && doesnt seem to work in my RStudio, is there a way to look this up online? – Kiwi Nov 04 '14 at 20:47
  • See my edited comment. The important part of the help file is: "& 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." – talat Nov 04 '14 at 20:48
  • 1
    You need to quote `?"&&"` – Rich Scriven Nov 04 '14 at 20:48
  • See also this answer http://stackoverflow.com/a/6559049/210673 – Aaron left Stack Overflow Nov 04 '14 at 20:55

0 Answers0