On 2/11/06, Patricia J. Hawkins <[EMAIL PROTECTED]> wrote: > >>>>> "iw" == ivo welch <[EMAIL PROTECTED]> writes: > > iw> * SUGGESTION: can we please offer the "?:" operator ala C in > iw> addition to ifelse()? This would make R code prettier. > > R: > if (condition) xxx else yyy > if (condition) xxx else if (yyy) zzz else qqq > > C: > condition ? xxx : yyy; > condition ? xxx : yyy ? zzz : qqq; > > If this is a beauty contest, or a readability contest, I'll take R! > > ?: is pleasant in C because it avoids so much of the C syntactic > sugar, of which R is largely free. > > As for ifelse(), for a trivial example, try running: > ifelse(array(rep(c(1,0), 50), dim=c(10,10)), "00", "99")
Maybe this is not the point but in this particular example we could write: matrix(c("00", "99"), 10, 10) > > iw> Similarly, perl has a nice construct, which would be lovely, but > iw> which may not jive with the > iw> R syntax: > iw> condition or die("the condition", condition, "has failed"); > iw> condition and cat("my condition", condition, "is met"); > > if (!condition) stop("the condition", condition, "has failed") > if (condition) cat("my condition", condition, "is met") > Try this: stopifnot(condition) > -- > Patricia J. Hawkins > Hawkins Internet Applications > www.hawkinsia.com > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html