[R] difference between ifelse and if...else?
MacQueen, Don
macqueen1 at llnl.gov
Wed Dec 13 22:46:58 CET 2017
Because ifelse is not intended to be an alternative to if ... else. They exist for different purposes.
(besides the other replies, a careful reading of their help pages, and trying the examples, should explain the different purposes).
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 12/13/17, 7:31 AM, "R-help on behalf of Jinsong Zhao" <r-help-bounces at r-project.org on behalf of jszhao at yeah.net> wrote:
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
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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