[R] difference between ifelse and if...else?

Jinsong Zhao jszhao at yeah.net
Wed Dec 13 16:31:29 CET 2017


Hi there,

I don't know why the following codes are return different results.

 > ifelse(3 > 2, 1:3, length(1:3))
[1] 1
 > if (3 > 2) 1:3 else length(1:3)
[1] 1 2 3

Any hints?

Best,
Jinsong



More information about the R-help mailing list