title: Why does the ifelse function return only the first element of a vector provided as an argument?
body: <p>I was puzzled by the result of the following R code:</p>
  <pre><code>ifelse(TRUE, c(2, 3, 4), &quot;a&quot;)
  #[1] 2
  </code></pre>
  <p>The result is <code>2</code>, but I expected to be <code>2, 3, 4</code>. Why is this?</p>