search for: ifelse2

Displaying 18 results from an estimated 18 matches for "ifelse2".

Did you mean: ifelse
2016 Nov 22
0
ifelse() woes ... can we agree on a ifelse2() ?
...eady been brought up, but I wonder what exactly you > mean when you want recycling behavior. Thank you, Gabe. Note that my premise was really to get *away* from inheriting too much from 'test'. Hence, I have *not* been talking about replacing ifelse() but rather of providing a new ifelse2() [ or if_else() if Hadley was willing to ditch the dplyr one in favor of a base one] > Specifically, based on an unrelated discussion with Henrik Bengtsson on > Twitter, I wonder if preserving the recycling behavior test is longer than > yes, no, bu...
2016 Nov 15
2
ifelse() woes ... can we agree on a ifelse2() ?
...age for userRs in a useful way. I suspect it's easy to forget that the result is not guaranteed to be the length of test, even for intermediate and advanced users familiar with ifelse and it's strengths/weaknesses. I certainly agree (for what that's worth...) that x = rnorm(100) y = ifelse2(x > 0, 1L, 2L) should continue to work. Also, If we combine a stricter contract that the output will always be of length with the suggestion of a specified output class the pseudo code could be ifelse2 = function(test, yes, no, outclass) { lenout = length(test) out = as( rep(yes, length.ou...
2016 Nov 27
0
ifelse() woes ... can we agree on a ifelse2() ?
...ot; from my previous E-mail was the beginning of message from Gabriel Becker, that I quoted. The quoted "still a bit disappointed that nobody has taken a look" is from Martin Maechler. In all of the proposed 'ifelse'-like functions so far, including from me (that I labeled as 'ifelse2', following Martin Maechler) and from Martin Maechler, the length of the result equals the length of 'test', like in 'ifelse'. There is no recycling of 'test'. ----------------------------------------- > Just stating, in 'ifelse', 'test' is not recy...
2016 Nov 27
1
ifelse() woes ... can we agree on a ifelse2() ?
...lt is 3. In fact, the length of the result is 1. I realize just now that the length of 'no' is different from 'yes'. The length of 'yes' is 3, the length of 'no' is 4. -------------------------------------------- Subject: Re: ifelse() woes ... can we agree on a ifelse2() ? To: R-devel at lists.R-project.org Date: Sunday, 27 November, 2016, 8:50 AM In all of the proposed 'ifelse'-like functions so far, including from me (that I labeled as 'ifelse2', following Martin Maechler) and from Martin Maechler, the length of the result equals the length...
2017 Nov 04
1
ans[nas] <- NA in 'ifelse' (was: ifelse() woes ... can we agree on a ifelse2() ?)
Removal of ans[nas] <- NA from the code of function 'ifelse' in R is not committed (yet). Why? -------------------------------------------- On Mon, 28/11/16, Martin Maechler <maechler at stat.math.ethz.ch> wrote: Subject: Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ? Cc: R-devel at r-project.org, maechler at stat.math.ethz.ch Date: Monday, 28 November, 2016, 10:00 PM >>>>> Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org> >>>>> on Sat, 26 Nov 2016 17:14:01 +0000 writes: ... > On cur...
2016 Nov 28
0
ifelse() woes ... can we agree on a ifelse2() ?
...), "zoo", "sparseVector", "sparseMatrix" (*), or "mpfr", without any special code, but rather by design. *) Currently needs the R-forge version of Matrix, version 1.2-8. A bit less than an hour ago, I have updated the gist with an updated proposal ifelse2() {and the current alternatives that I know}, modified so it *does* keep more, e.g. dim() attributes in reasonable cases. https://gist.github.com/mmaechler/9cfc3219c4b89649313bfe6853d87894#file-ifelse-def-r-L168 Hence my ifelse2() became even a bit longer (but not slower) working for even more c...
2016 Nov 15
0
ifelse() woes ... can we agree on a ifelse2() ?
...p_id=386) > But of course that wouldn't help with factor responses. Yes. However, a version of Duncan's suggestion -- of treating 'yes' first -- does help in that case. For once, mainly as "feasability experiment", I have created a github gist to make my current ifelse2() proposal available for commenting, cloning, pullrequesting, etc: Consisting of 2 files - ifelse-def.R : Functions definitions only, basically all the current proposals, called ifelse*() - ifelse-checks.R : A simplistic checking function and examples calling it, notably demonstrating...
2016 Nov 26
3
ifelse() woes ... can we agree on a ifelse2() ?
...n without fourth argument. The part should be wrapped in if(has.4th) . * Function 'ifelseJH' has fourth argument, but the argument is not for value if NA. So, instead of chkIfelse(ifelseJH) , maybe call chkIfelse(function(test, yes, no) ifelseJH(test, yes, no)) . A concrete version of 'ifelse2' that starts the result from 'yes': function(test, yes, no, NA. = NA) { ? ? if(!is.logical(test)) ? ? ? ? test <- if(isS4(test)) methods::as(test, "logical") else as.logical(test) ? ? n <- length(test) ? ? ans <- rep(yes, length.out = n) ? ? ans[!test & !is.na(tes...
2016 Aug 15
2
ifelse() woes ... can we agree on a ifelse2() ?
On Fri, Aug 12, 2016 at 11:31 AM, Hadley Wickham <h.wickham at gmail.com> wrote: >> >> One possibility would also be to consider a "numbers-only" or >> >> rather "same type"-only {e.g., would also work for characters} >> >> version. >> >> > I don't know what you mean by these. >> >> In the
2016 Aug 07
1
ifelse() woes ... can we agree on a ifelse2() ?
...but that currently fails as the C-low-level dispatch for '[<-' >> does not look at the full signature >> ]] >> >> I vaguely remember having seen proposals for >> light weight substitutes for ifelse(), called >> ifelse1() or >> ifelse2() etc... >> >> and I wonder if we should not try to see if there was a version >> that could go into "base R" (maybe the 'utils' package, not >> 'base'; that's not so important). >> >> One difference to...
2016 Nov 29
0
ifelse() woes ... can we agree on a ifelse2() ?
Interspersed below. -------------------------------------------- Subject: Re: ifelse() woes ... can we agree on a ifelse2() ? To: R-devel at lists.R-project.org Date: Sunday, 27 November, 2016, 12:14 AM On current 'ifelse' code in R: ... * If 'test' is a factor, doing storage.mode(test) <- "logical" is not appropriate, but is.atomic(test) returns TRUE. Maybe use if(!is.object(test)) in...
2016 Aug 06
0
ifelse() woes ... can we agree on a ifelse2() ?
...lue) .........) > > but that currently fails as the C-low-level dispatch for '[<-' > does not look at the full signature > ]] > > I vaguely remember having seen proposals for > light weight substitutes for ifelse(), called > ifelse1() or > ifelse2() etc... > > and I wonder if we should not try to see if there was a version > that could go into "base R" (maybe the 'utils' package, not > 'base'; that's not so important). > > One difference to ifelse() would be that the type/...
2016 Aug 12
0
ifelse() woes ... can we agree on a ifelse2() ?
> >> One possibility would also be to consider a "numbers-only" or > >> rather "same type"-only {e.g., would also work for characters} > >> version. > > > I don't know what you mean by these. > > In the mean time, Bob Rudis mentioned dplyr::if_else(), > which is very relevant, thank you Bob! > > As I have
2016 Aug 06
4
ifelse() woes ... can we agree on a ifelse2() ?
...;), function(x,i,value) .........) but that currently fails as the C-low-level dispatch for '[<-' does not look at the full signature ]] I vaguely remember having seen proposals for light weight substitutes for ifelse(), called ifelse1() or ifelse2() etc... and I wonder if we should not try to see if there was a version that could go into "base R" (maybe the 'utils' package, not 'base'; that's not so important). One difference to ifelse() would be that the type/mode/class of the result is...
2016 Aug 12
2
ifelse() woes ... can we agree on a ifelse2() ?
...urrently fails as the C-low-level dispatch for '[<-' >> does not look at the full signature >> ]] >> >> I vaguely remember having seen proposals for >> light weight substitutes for ifelse(), called >> ifelse1() or >> ifelse2() etc... >> >> and I wonder if we should not try to see if there was a version >> that could go into "base R" (maybe the 'utils' package, not >> 'base'; that's not so important). >> >> One difference to ifel...
2004 May 20
2
ifelse when test is shorter than yes/no
Hi, It turns out that the 'test' vector in ifelse(test, yes, no) is not recycled if it is shorter than the other arguments, e.g. > ifelse(TRUE, seq(10), -seq(10)) [1] 1 Is there any particular reason it is not recycled? If there is one indeed a warning message might be in order when someone calls ifelse with a shorter 'test'. This is R1.8.1 on RH-7.3 Thanks, Vadim
2018 May 08
1
Proposed speedup of ifelse
...in contributing to R and helping it continue to get better. And I think, and my local experiments bear out, that using anyNA as a fastpass condition does allow us to get a significant speedup over what's in there now. To do so, though, I took a somewhat different approach than your proposal: ifelse2 = function(test, yes, no) { if (is.atomic(test)) { if (typeof(test) != "logical") storage.mode(test) <- "logical" if (length(test) == 1 && is.null(attributes(test))) { if (is.na(test)) return(NA)...
2018 May 03
2
Proposed speedup of ifelse
> I propose a patch to ifelse that leverages anyNA(test) to achieve an > improvement in performance. For a test vector of length 10, the change > nearly halves the time taken and for a test of length 1 million, there > is a tenfold increase in speed. Even for small vectors, the > distributions of timings between the old and the proposed ifelse do > not intersect. For smaller