t; sim2"," the2"),
>
> values = c(1:4))
>
>
>
> Mayooran
>
>
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
>
>
> From: Richard O'Keefe<mailto:rao...@gmail.com
f Newmiller<mailto:jdnew...@dcn.davis.ca.us>
Cc: R-help mailing list<mailto:r-help@r-project.org>; peter
dalgaard<mailto:pda...@gmail.com>
Subject: Re: [R] need help in if else condition
I didn't communicate my problem to R-Sig-Debian because I had never
previously
heard
> However, having installed "Action of the Toes" (are R releases named
> by Culture AIs, by any chance?)
Peanuts cartoons.
https://twitter.com/snoopy/status/269963551135891456
Steve E
***
This email and any attachments are confid
I didn't communicate my problem to R-Sig-Debian because I had never
previously
heard of them. Thank you for the tip.
Poking through the recent archives there I see other people
have had (different) trouble with the Bionic repository.
Fortunately, the instructions at
https://linuxize.com/post/how-
Did you ask for assistance on R-Sig-Debian? you will need to be more explicit
than below about what you actually did. FWIW I was able to do it [1]... you
might have encountered a temporary network problem.
[1] https://cran.r-project.org/bin/linux/ubuntu/README.html
On July 14, 2019 4:55:25 PM C
Four-core AMD E2-7110 running Ubuntu 18.04 LTS.
The R version is the latest in the repository:
r-base/bionic,bionic,now 3.4.4-1ubuntu1 all [installed]
Why not 3.6? Because when i followed the installation instructions, adding
deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
to /e
One common gotcha is that ifelse() has no way to reconcile attributes between
the two alternatives so it takes the attributes for the result from those of
the condition, which is almost certainly what you don't want. In particular,
this may convert factors to their underlying integer codes.
An
Er, what version is this? I have (on a late 2010 MB Air!)
> system.time(ifelse(x < y, x, y))
user system elapsed
0.072 0.012 0.085
and even
> system.time({r<-numeric(100);ix <- x < y; r[ix]<-x[ix]; r[!ix]<-y[!ix];
> r})
user system elapsed
0.082 0.053 0.135
-pd
>
"ifelse is very slow"? Benchmark time.
> x <- runif(100)
> y <- runif(100)
> system.time(ifelse(x < y, x, y))
user system elapsed
0.403 0.044 0.448
> system.time(y + (x < y)*(x - y))
user system elapsed
0.026 0.012 0.038
This appears to be a quality-of-implementation b
On 10/07/2019 11:54 a.m., Richard O'Keefe wrote:
Expectation: ifelse will use the same "repeat vectors to match the longest"
rule that other vectorised functions do. So
a <- 1:5
b <- c(2,3)
ifelse(a < 3, 1, b)
=> ifelse(T T F F F <<5>>, 1 <<1>>, 2 3 <<2>>)
=> ifelse(T T F F F <<5>>, 1 1 1 1 1 <<
On 7/10/19 5:54 PM, Richard O'Keefe wrote:
Expectation: ifelse will use the same "repeat vectors to match the longest"
rule that other vectorised functions do. So
a <- 1:5
b <- c(2,3)
ifelse(a < 3, 1, b)
=> ifelse(T T F F F <<5>>, 1 <<1>>, 2 3 <<2>>)
=> ifelse(T T F F F <<5>>, 1 1 1 1 1 <<5>>
Sigh. I don't agree with this "avoid ifelse because you might not know the
shape of the arguments" advice. All R variables have shapes and sizes, and the
better advice is to _pay attention to shapes and sizes_, especially when using
vectorized functions like ifelse. An easy way to maintain shape
Of course the behavior of ifelse is predictable.
My point was that for newb's (I was one once) you can get burned if you
don't appreciate that ifelse is vectorized.
Especially if you have some "muscle memory" from using ifelse() in Excel.
On Wed, Jul 10, 2019 at 6:55 PM Richard O'Keefe wrote:
>
Expectation: ifelse will use the same "repeat vectors to match the longest"
rule that other vectorised functions do. So
a <- 1:5
b <- c(2,3)
ifelse(a < 3, 1, b)
=> ifelse(T T F F F <<5>>, 1 <<1>>, 2 3 <<2>>)
=> ifelse(T T F F F <<5>>, 1 1 1 1 1 <<5>>, 2 3 2 3 2 <<5>>)
=> 1 1 2 3 2
and that is inde
The answer here is that in "ifelse(a < 3, ..)" you ALWAYS expect "a" to
be
a vector because there would be no point in using ifelse if it weren't.
If you believe that "a" is or ought to be a single number, you write
x <- if (a < 3) 1 else 2
The whole point of ifelse is to vectorise.
On Thu,
Or even
> a <- 1:5
> [lots of other code]
> x <- ifelse( a < 3, 1, 2)
The point (in this example) is that you might have introduced a bug because
you forgot that 'a' is a vector.
Looking (in isolation) at the assignment to 'x' you believe it's going to
be a single number, either 1 or 2 (unless you
For example, can you predict what the following code will do?
> a <- 1:5
> b <- c(2,3)
> ifelse( a < 3, 1, b)
On Wed, Jul 10, 2019 at 4:34 PM José María Mateos
wrote:
> On Wed, Jul 10, 2019, at 04:39, Eric Berger wrote:
> > 1. The ifelse() command is a bit tricky in R. Avoiding it is often a go
On Wed, Jul 10, 2019, at 04:39, Eric Berger wrote:
> 1. The ifelse() command is a bit tricky in R. Avoiding it is often a good
> policy.
You piqued my curiosity, can you elaborate a bit more on this?
--
José María (Chema) Mateos || https://rinzewind.org
_
Since this has already been answered, I'll just mention one point that was
not addressed.
> d=c(1,2,3,"-","dnr","post",10)
This is rather odd.
> str(d)
chr [1:7] "1" "2" "3" "-" "dnr" "post" "10"
You can create a vector of logical values, or a vector of numbers, or a
vector of strings,
but if ther
Hello Eric,
Thank you, it worked. both approach.
On Wed, Jul 10, 2019 at 2:09 PM Eric Berger wrote:
> Change the definition of de to
>
> de <- data.frame(d,e,stringsAsFactors=FALSE)
>
> Then you should be ok.
>
> Some additional remarks:
>
> 1. The ifelse() command is a bit tricky in R. Avoiding
Change the definition of de to
de <- data.frame(d,e,stringsAsFactors=FALSE)
Then you should be ok.
Some additional remarks:
1. The ifelse() command is a bit tricky in R. Avoiding it is often a good
policy.
2. I find %in% very useful. You could replace the multiple conditions check
de$d=="-
Hello all,
I am trying to run if else condition to alter my data. I have created a
column F with reference to column d where I want to replace the value to
0 where ever it finds a string or character value like -,dnr, post and
keep the rest of the rows should have the original value of column d.
22 matches
Mail list logo