similar to: ifelse when test is shorter than yes/no

Displaying 20 results from an estimated 20000 matches similar to: "ifelse when test is shorter than yes/no"

2016 Nov 26
3
ifelse() woes ... can we agree on a ifelse2() ?
Just stating, in 'ifelse', 'test' is not recycled. As I said in "R-intro: length of 'ifelse' result" (https://stat.ethz.ch/pipermail/r-devel/2016-September/073136.html), ifelse(condition, a, b) returns a vector of the length of 'condition', even if 'a' or 'b' is longer. On current 'ifelse' code in R: * The part ans[nas] <- NA
2016 Nov 15
2
ifelse() woes ... can we agree on a ifelse2() ?
All, Martin: Thanks for this and all the other things you are doing to both drive R forward and engage more with the community about things like this. Apologies for missing this discussion the first time it came around and if anything here has already been brought up, but I wonder what exactly you mean when you want recycling behavior. Specifically, based on an unrelated discussion with Henrik
2003 Feb 19
4
fitting a curve according to a custom loss function
Dear R-Users, I need to find a smooth function f() and coefficients a_i that give the best fit to y ~ a_0 + a_1*f(x_1) + a_2*f(x_2) Note that it is the same non-linear transformation f() that is applied to both x_1 and x_2. So my first question is how can I do it in R? A more general question is this: suppose I have a utility function U(a_i, f()), where f() is say a spline. Is there a general
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
2004 May 01
5
skip lines on a connection
Hi, I am looking for an efficient way of skipping big chunks of lines on a connection (not necessarily at the beginning of the file). One way is to use read lines, e.g. readLines(1e6), but a) this incurs the overhead of construction of the return char vector and b) has a (fairly remote) potential to blow up the memory. Another way would be to use scan(), e.g. scan(con, skip=1e6, nmax=0)
2016 Aug 06
4
ifelse() woes ... can we agree on a ifelse2() ?
Dear R-devel readers, ( = people interested in the improvement and development of R). This is not the first time that this topic is raised. and I am in now state to promise that anything will result from this thread ... Still, I think the majority among us has agreed that 1) you should never use ifelse(test, yes, no) if you know that length(test) == 1, in which case if(test) yes
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
2016 Aug 07
1
ifelse() woes ... can we agree on a ifelse2() ?
On 06.08.2016 17:30, Duncan Murdoch wrote: > On 06/08/2016 10:18 AM, Martin Maechler wrote: >> Dear R-devel readers, >> ( = people interested in the improvement and development of R). >> >> This is not the first time that this topic is raised. >> and I am in now state to promise that anything will result from >> this thread ... >> >> Still, I
2001 Sep 17
3
computational capacity of Linux network
Hi, This is not an R question per ce, but I feel like this is a right community to ask it. As a part of our work we run a lot of non-interactive computational jobs. To increase the throughput we would like to distribute the load over the entire network and we are looking at Linux network as a platform. Ideally we would like to be able to submit a job to the network, rather than to a computer, and
2003 Sep 03
3
read.table: check.names arg - feature request
Hi, I thought it would be convenient if the check.names argument to read.table, which currently can only be TRUE/FALSE, could take a function value as well. If the function is supplied it should be used instead of the default make.names. Here is an example where it can come in handy. I tend to keep my data in coma-separated files with a header line. The header line is prefixed with a comment
2005 Mar 08
4
how modify object in parent.env
Hi, Is it possible to modify an object in the parent.env (as opposed to re-bind)? Here is what I tried: > x = 1:3 # try to modify the first element of x from within a new environment > local(get("x", parent.env(environment()))[1] <- NA) Error in eval(expr, envir, enclos) : Target of assignment expands to non-language object # On the other hand retrieval works just fine >
2004 Jun 14
5
mkChar can be interrupted
Hi, As was discussed earlier in another thread and as documented in R-exts .Call() should not be interruptible by Ctrl-C. However the following code, which spends most of its time inside mkChar, turned out to be interruptible on RH-7.3 R-1.8.1 gcc-2.96: #include <Rinternals.h> #include <R.h> SEXP foo0(const SEXP nSexp) { int i, n; SEXP resSexp; if (!isInteger(nSexp))
2005 May 07
4
how to add method to .Primitive function
Hi, I tried to write the dim method for the list class, but R doesn't seem to dispatch to it: > dim.list = function(x) c(length(x[[1]]), length(x)) > dim(list(1)) NULL > dim.list(list(1)) [1] 1 1 What is the correct way of registering dim.list with .Primitive("dim")? Thanks, Vadim [[alternative HTML version deleted]]
2005 Apr 12
5
How allocate STRSXP outside of gc
Hi, I am trying to figure a way to allocate a string SEXP so that gc() won't ever collect it. Here is a little bit of a background. Suppose I want to write a .Call-callable function that upon each call returns the same value, say mkChar("foo"): SEXP getFoo() { return mkChar("foo"); } The above implementation doesn't take advantage of the fact that
2004 Mar 17
4
why-s of method dispatching
Hi, I am having a problem to understand why as.data.frame method doesn't dispatch properly on my class: > setClass("Foo", "character") [1] "Foo" > as.data.frame(list(foo=new("Foo", .Data="a"))) Error in as.data.frame.default(x[[i]], optional = TRUE) : can't coerce Foo into a data.frame I was expecting that this would call
2005 Apr 18
4
longer object length, is not a multiple of shorter object length in: kappa * gcounts
Hi, I was using a density estimation function as follows: > est <- KernSmooth::bkde(x3, bandwidth=10) When setting bandwidth less than 5, I got the error "longer object length, is not a multiple of shorter object length in: kappa * gcounts ". I wonder if there is anybody who can explain the error for me? Thanks! Hui
2005 May 31
2
A suggestion to improve ifelse behaviour with vector yes/no arguments
Dear All, I luckily found the following feature (or problem) when tried to apply ifelse-function to an ordered data. > test <- c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) > ifelse(test, 0, 1:4) [1] 0 0 0 4 1 2 3 > It roots into the ifelse-syntax: ans[!test & !nas] <- rep(no, length.out = length(ans))[!test & !nas] Would it be possible to disable this feature in the
2004 Dec 03
4
seq.Date requires by
Hi, What is the reason for seq.Date to require the 'by' argument and not to default it to 1 in the example below? > seq(from=as.Date("1996-01-01"), to=as.Date("1996-12-01")) Error in seq.Date(from = as.Date("1996-01-01"), to = as.Date("1996-12-01")) : exactly two of `to', `by' and `length.out' / `along.with' must be specified
2016 Nov 27
1
ifelse() woes ... can we agree on a ifelse2() ?
Related to the length of 'ifelse' result, I want to say that "example of different return modes" in ?ifelse led me to perceive a wrong thing in the past. ## example of different return modes: yes <- 1:3 no <- pi^(0:3) typeof(ifelse(NA, yes, no)) # logical typeof(ifelse(TRUE, yes, no)) # integer typeof(ifelse(FALSE, yes, no)) # double As
2005 Mar 22
1
documentation on seek *does not* need update
Well, "integer" is also a storage.mode in R. It is not immediately clear which meaning the help page uses. I guess some extra elaboration would be helpful. Anyway, thank you for the clarification, Vadim > -----Original Message----- > From: Prof Brian Ripley [mailto:ripley@stats.ox.ac.uk] > Sent: Tuesday, March 22, 2005 9:54 AM > To: Vadim Ogranovich > Cc: