Displaying 20 results from an estimated 2319 matches for "ifelses".
Did you mean:
ifelse
2011 Sep 12
1
nested anova<-R chrashing
Hi,
I tried to do a nested Anova with the attached Data. My response
variable is "survivors" and I would like to know the effect of
(insect-egg clutch) "size", "position" (of clutch on twig) and "clone"
(/plant genotype) on the survival of eggs (due to predation). Each plant
was provided with three different sizes of clutches (45,15,5) and had
2008 Oct 20
5
Combining all possible values of variables into a new...
I'm trying to create a new column in my data.frame where subjects are categorized depending on values on four other columns. In any other case I would just nest a few ifelse statements, however, in this case i have 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I wonder if there is a more efficient way of doing this.
For illustrational purposes, let's say
2008 Nov 19
2
simplify this instruction
Hi R users,
Is there a way to simplify this instruction:
ifelse(B=="0","A",
ifelse(B=="1","A",
ifelse(B=="2","A",
ifelse(B=="3","A",
ifelse(B=="4","A",
ifelse(B=="5","A",
ifelse(B=="6","A",
ifelse(B=="7","A",
2012 Aug 24
6
updating elements of a vector sequentially - is there a faster way?
I would like to know whether there is a faster way to do the below
operation (updating vec1).
My objective is to update the elements of a vector (vec1), where a
particular element i is dependent on the previous one. I need to do this on
vectors that are 1 million or longer and need to repeat that process
several hundred times. The for loop works but is slow. If there is a faster
way, please let
2009 Feb 10
7
ifelse()
I have a problem with ifelse(), I do not understand how it works.
> X<-c(2,2,1,1,0,0)
> str(X)
num [1:6] 2 2 1 1 0 0
> Y<-ifelse(X>0,1,0)
> Y
[1] 1 1 1 1 0 0
>
Can some one explain what is going on, I do not understand what ifelse is
doing in this case. Can someone explain the output Y.
Thanks
--
View this message in context:
2010 May 26
4
More efficient way to use ifelse()?
# This is more about trying to find a more effecient way to code some
simple vectorized computations using ifelse().
# Say you have some vector representing a factor with a number of
levels (6 in this case), representing the location that samples were
collected.
Population <- gl( n=6, k=5,length=120, labels =c("CO", "CN","Ga","KO",
"Mw",
2010 Mar 10
1
ifelse logic and multiple assignments
I'm a fairly new R user and while I have a solution to my problem I'm
wondering if there is a better one.
In SAS it's common to use if/then logic along with a "do" statement to
make several things happen. While I could do the same thing in R
using a "for" loop, and "if" and {}, I've read that loops are less
common in R and I wonder if I'm doing
2005 Jun 27
2
simplifying the code
dear list:
I need help to achieve a simpler code to complete a
task I'm performing.
here is an example:
dat<-expand.grid(a=seq(1,5),b=seq(1000,1005))
I want to add a new column dat$c in that:
t1<-ifelse(dat$a==1&dat$b==1001,1001,0)
t2<-ifelse(dat$a==2&dat$b==1002,1001,0)
t3<-ifelse(dat$a==3&dat$b==1003,1001,0)
t4<-ifelse(dat$a==1&dat$b==1002,1002,0)
2009 Feb 13
2
extracting parts of words or extraxting letter to use in ifelse-func.
Hello
I want to make some variables with the ifelse-function, but i don't know how
to do it.
I want to make these five variables;
b2$PRRSvac <- ifelse(b2$status=='A' | b2$status=='Aa',1,0)
b2$PRRSdk <- ifelse(b2$status=='B' | b2$status=='Bb',1,0)
b2$sanVac <- ifelse(b2$status=='C' | b2$status=='sanAa',1,0)
b2$sanDk <-
2007 Apr 17
3
Is this a bug?
I have found a strange "ifelse" behaviour (I think)
This works:
> ifelse(T,1+1,1+2)
[1] 2
> ifelse(F,1+1,1+2)
[1] 3
Maybe I missed something about R internals, but why
> ifelse(T,print("hello"),print("goodbye"))
[1] "hello"
[1] "hello"
> ifelse(F,print("hello"),print("goodbye"))
[1] "goodbye"
[1]
2009 Oct 24
2
ifelse
When I run this code from an R-script:
ddd = 360 + round ( atan2(-u,-v) / d2r )
print(class(ddd))
print(ddd)
ifelse ( ddd>360, ddd-360, ddd )
print(ddd)
I get this output:
[1] "numeric"
[1] 461 213 238 249 251
[1] 461 213 238 249 251
Why does ifelse not change the 461 to 101?
I recreated the vector ddd and ran the same ifelse
code
2005 Jun 22
2
Trouble with ifelse and if statement (PR#7962)
Full_Name: Woolton Lee
Version: 2.1
OS: windows
Submission from: (NULL) (128.118.224.46)
I did the following ('g' and 'h' are both numeric vectors)
> i <- abs(g-h)
creating a vector 'i' with values,
> i
[1] 0.08 0.00 0.33 0.00 0.00 0.00 0.00 0.33 0.00 0.00 0.08 0.08 0.20 0.00 0.13
Now, I want to create a new vector =1 whenever 'i' = 0.33 and =0
2010 Feb 23
3
Use 2 "ifelse" to sort data
Dear R users,
I have a question how to use 2 "ifelse" to sort my data. Such as
from 11 to 20 assign to A; 6 to 10 assign to B, and the rest of them assign
to C
a<-1:20
tt<-ifelse(a>10, "A",no=ifelse( 5< a <=10, "B", "C"))
Many Thanks
Chunhao
--
View this message in context:
2010 Aug 18
5
ifelse command
hello people,
I want to make a biased dice using the sample() function and print out the
results after n number of runs, I've successfully generated the dice using
the following command:
mydie2<-function(n=1000,y=NULL,...){
for(i in 1:n){
x<-sample(1:6,n,replace=TRUE,prob=c(1,1,2,3,2,1)/10)
x=runif(n)
if(x<=1/10){y[i]=1}
else if(x<=2/10){y[i]=2}
else if(x<=4/10){y[i]=3}
else
2018 May 03
1
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.
The patch does not intend to change the
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
2012 Jan 19
3
Establishing groups using something other than ifelse()
Hello all,
This is one of those "Is there a better way to do this questions". Say
I have a dataframe (df) with a grouping variable (z). This is my base
data. Now I know that there is a higher order level of grouping that
exist for my group variable. So what I want to do is create a new
column that express that higher order level of grouping based on
values in the sub-group (z in this
2010 Dec 09
1
set dataframe field value from lookup table
Hi
This is (hopefully) a bit more cogent phrasing of a previous post. I'm
trying to compute a z-score to rows in a large dataframe based on values in
another dataframe. Here's the script (that does not work). 2 questons,
1) Anyone know of a more elegant way to calculate the "rounded" age value
than the nested ifelse's I've used?
2) how to reference the lookup table
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.
> >>>
> >>>
>
2023 Aug 10
2
Expresión en un objeto
Hola a todos:
Se me ha planteado un problema que no está ligado a ningún problema
concreto. Es más teórico.
Supongamos que tenemos tres variables:
V1 <- c (47, 71, 41, 23, 83, 152, 82, 8, 160, 18)
V2a <- c (NA, 36, 15, 5, 56, 18, NA, 5, NA, 5)
V2b <- c (37, NA, 15, NA, NA, NA, 90, NA, 161, NA)
Supongamos que tengo la expresión (que no puedo asignarlo a