Displaying 20 results from an estimated 10000 matches similar to: "Error message in ifthen else"
2004 Feb 27
2
question about if else
Today is a good day for asking question, I guess.
> c()
NULL
>
> length(c())==0
[1] TRUE
>
> r = ifelse(length(c())!=0, c(), c(1,2)) ### OK
> r = c() ### OK
> r = ifelse(length(c())==0, c(), c(1,2)) ### why this is not OK (given
> the previous two)?
Error in "[<-"(`*tmp*`, test, value = rep(yes, length =
2010 Mar 04
0
ifthen() question -- whoops--ifelse()
OK, I got it figured out. I was not keying into a length greater than 1, so:
# I added this object and placed it into the iftelse statement:
lid <- sum(match(id, st[i], nomatch = 0))
out$var.g[i]<-ifelse(lid ==1, meta$var.g[id==st[i]],
aggs(g=g[id==st[i]],
n.1= n.1[id==st[i]],
n.2 = n.2[id==st[i]], cor)[2])
#full
2010 Mar 04
1
ifthen() question
Hi All,
I am using a specialized aggregation function to reduce a dataset with
multiple rows per id down to 1 row per id. My function work perfect when
there are >1 id but alters the 'var.g' in undesirable ways when this
condition is not met, Therefore, I have been trying ifthen() statements to
keep the original value when length of unique id == 1 but I cannot get it to
work. e.g.:
2005 Jun 01
2
A suggestion to improve ifelse behaviour with vector yes/noarguments
> Thomas Lumley wrote:
> > On Tue, 31 May 2005, Duncan Murdoch wrote:
> >
> >
> >>M??kinen Jussi wrote:
> >>
> >>>Dear All,
> >>>
> >>>I luckily found the following feature (or problem) when tried to
> >>>apply
> >>>ifelse-function to an ordered data.
> >>>
> >>>
>
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
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
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
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
2018 May 08
1
Proposed speedup of ifelse
Hugh,
(Note I speak for myself only and not for R-core) Thanks for looking into
this. I think it's great to have community members that are interested 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
2016 Aug 12
2
ifelse() woes ... can we agree on a ifelse2() ?
Excuse for the delay; I had waited for other / additional
comments and reactions (and been distracted with other urgent issues),
but do want to keep this thread alive [inline] ..
>>>>> Duncan Murdoch <murdoch.duncan at gmail.com>
>>>>> on Sat, 6 Aug 2016 11:30:08 -0400 writes:
> On 06/08/2016 10:18 AM, Martin Maechler wrote:
>> Dear
2008 Sep 27
2
[LLVMdev] SwitchInstr::removeCase() doesn't remove PHINodes' predecessors
Hi,
I've been writing an optimization pass (described on the ML previously).
Sometimes this pass removes some case entries from switch instructions,
which cause an abort because removeCase() doesn't fix the PHINodes
predecessors when needed.
e.g.:
define i32 @foo() nounwind {
ifthen:
%call = call i32 @bar()
switch i32 %call, label %myphi [
i32 0, label %ifelse
i32 1, label
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
2023 Oct 13
1
if-else that returns vector
?ifelse
'ifelse' returns a value with the same shape as 'test' which is
filled with elements selected from either 'yes' or 'no' depending
on whether the element of 'test' is 'TRUE' or 'FALSE'.
This is actually rather startling, because elsewhere in the
S (R) language, operands are normally replicated to the length
of the longer.
2017 Dec 13
0
difference between ifelse and if...else?
ifelse is vectorized.
On Wed, Dec 13, 2017 at 7:31 AM, Jinsong Zhao <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
>
>
2011 Aug 01
3
error in self-made function - cannot deal with objects of length = 1
I have a function to calculate the rate of increase (the difference between
the value and the previous value divided by the total number of eggs in a
year) of egg production over the course of a year:
rate <- function(x){
storage <- matrix(nrow=length(x),ncol=1)
storage[1,] <- x[1] / max(x) # as there is no previous value
for( i in 2:length(x)){
p <- i - 1
2011 Sep 16
3
Problematic If-Else statement
Hi guys,
My code (next 2 lines below) isn't doing what I'm expecting it to:
tmp <-
ifelse(uncurated$days_to_tumor_recurrence=="null","norecurrence","recurrence")
curated$recurrence_status <- tmp
I want the column "recurrence_status" in my output file to have values
"recurrence" (if the input value had a number in the
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
2009 Jun 08
5
if else
Hi R-helpers!
I have the following dataframe:
firm<-c(rep(1:3,4))
year<-c(rep(2001:2003,4))
X1<-rep(c(10,NA),6)
X2<-rep(c(5,NA,2),4)
data<-data.frame(firm, year,X1,X2)
data
So I want to obtain the same dataframe with a variable X3
that is:
X1, if X2=NA
X2, if X1=NA
X1+X2 if X1 and X2 are not NA
So my final data is
X3<-c(15,NA,12,5,10,2,15,NA,12,5,10,2)
2017 Dec 13
4
difference between ifelse and if...else?
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