Displaying 20 results from an estimated 2000 matches similar to: "Ifelse statement"
2010 Jul 07
1
ifelse statement
Hi, I am a newbie of R, and playing with the "ifelse" statement.
I have the following codes:
## first,
for(i in 1:3) {
for(j in 2:4) {
cor.temp <- cor(iris.allnum[,i], iris.allnum[,j])
if(i==1 & j==2) corr.iris <- cor.temp
else corr.iris <- c(corr.iris, cor.temp)
}
}
this code is working fine.
I also tried to perform the same thing in another way with "ifelse":
2010 Sep 17
1
ifelse statement
Dear list,
I have a question I'm trying to use the following command in R, but it gives
me an error message.The command is:
data<-ddply(data,c("year","name"), transform, check1=ifelse(check1==1 &
check2==1, 1,NULL))
so in my data frame I already have the check1 variable, if the conditions
(check1==1 & check2==1) is respected, check has to have 1 as value,
2008 Mar 05
1
FOR LOOP w/IFELSE statement help
Dear list,
I'm trying to query a string of numbers to identify where in the string the numbers stop increasing (where x[i] == x[i+1]). In example 1 below, I've adapted code from Jim Holt to do this. However, I run into situations where the condition is not met, as in example 2, where the number string is continuous. In this case, I need to specify an alternative outcome, where if in the
2005 Dec 13
2
creating a subset of a dataset using ifelse statement?
I am using R in a Microsoft Windows environment.
I have a dataset called “mp1b”. I have a variable called h.
h can take a value from -1 to 5.
If h <1, I want to create a new dataset called mp2 that is the same as mp1b:
“mp2<-mp1b”
If h > 0, I want to set create a dataset mp2, where I limit the original dataset to those where mp1b$group = =h. similar to:
2011 Mar 16
1
table() result issue
Dear reader,
I have the following problem:
I have some string with numbers like k. I want
to have a table like the function table() gives. However I am not able
to call the first row, the 1, 2, 3, 5, 6 or 9. I tried to do that by a
data.frame, but that doesn't seem to work either. The levels keep
bothering me.
This is an example of the code:
2010 Jul 21
1
xtable with ifelse statement
Hi there,
I'm very new on R and I hope someone can help me to solve the problem in
using the ifelse statement with the xtable function(library xtable).
I'm trying to get the printing of the elements of two lists in a sorted way.
These two list have in common the their names.
I will try to give an example:
the first list looks like this:
$code1
Code code1
Nation
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
2012 Mar 17
3
rtriang using ifelse statement
Hi All,
I want to draw samples (n=4) from one of 2 triangular distributions for
each value in a matrix. I am using an ifelse statement to try to define
which distribution to draw from.
>From the output, I can see that the ifelse statement is choosing the correct
distribution, however, my n=4 simulations aren't occurring. Is there a way
to adjust the ifelse statement to fix this, or must
2011 Mar 16
1
get information out of table() result
I have the following problem:
I have some string with numbers like k. I want to have a table like the
function table() gives. However I am not able to call the first row, the 1,
2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem
to work either. The levels keep bothering me.
This is an example of the code:
k<-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1)
> table(k)
k
1 2
2012 May 16
2
trouble with ifelse statement
Hello,
I apologize in advance for not providing sample data, I'm a very new to R
and can't easily generate appropriate sample data quickly. I'm hoping
someone can offer advice without it.
This code below works and does what I want it to do, which is for a given
row in my dataframe, where the variable "peak.cort" = max, it makes the
value of another variable
2009 Jun 23
2
Problem with ifelse statement
Hi R-helpers,
I am trying to use this ifelse statement to recode a variable:
> data$SOCIAL_STATUS<-ifelse(data$SOCIAL_STATUS=="B" & data$MALE>4, "C", "B")
(i.e., if social status is B and there are more than 4 males, then
recode social status to C; otherwise, leave it B)
But, it's not working. See the below R output. Notice that there were
71
2010 Jan 14
5
Better way than an ifelse statement?
Hello All,
I am trying to create a column of weights based off of factor levels
from another column. I am using the weights to calculate L scores.
Here is an example where the first column are scores, the second is my
"factor" and the third I want to be a column of weights. I can do
what I want with an ifelse statement (see below), but I am wondering
if anyone knows of a cleaner way
2012 Jun 18
6
Trying to speed up an if/else statement in simulations
Dear R-help,
I am trying to write a function to simulate datasets of size n which contain
two time-to-event outcome variables with associated 'Event'/'Censored'
indicator variables (flag1 and flag2 respectively). One of these indicator
variables needs to be dependent on the other, so I am creating the first and
trying to use this to create the second using an if/else statement.
2011 Apr 05
2
IFELSE function XXXX
Hello everyone,
This IFELSE function call is not working properly. I do not receive an error
message, but the actions are not executed conditional as I was hoping. Any
assistance is appreciated.
set.seed(12345)
res1<-rbinom(10000,1,.1)
rdata3<-transform(data.frame(res1),input1=rnorm(10000,50,10))
data3
#inducing correlation between res1 & input1
2009 Jun 24
5
How to avoid ifelse statement converting factor to character
Hi R-helpers,
Please see the below R output.
The problem is that after running the ifelse statement, data$SOCIAL_STATUS
is converted from a factor to a character.
Is there some way I can avoid this conversion?
Thanks in advance, Mark Na
> str(data)
'data.frame': 2100 obs. of 11 variables:
$ DATE : Factor w/ 5 levels "4-Jun-09","7-May-09",..: 1 1 1 1 1
2011 Mar 16
4
table() reading problem
I have the following problem:
I have some string with numbers like k. I want to have a table like the
function table() gives. However I am not able to call the first row, the 1,
2, 3, 5, 6 or 9. I tried to do that by a data.frame, but that doesn't seem
to work either. The levels keep bothering me.
This is an example of the code:
k<-c(1,1,1,1,1,3,5,6,2,1,3,9,2,3,1,1,1)
> table(k)
k
1 2
2017 Jul 24
0
Ifelse statements and combining columns
Not a reproducible example, so a bit of guessing here, but
a) don't try to assign results to variables inside the ifelse. That is, remove all the single-equals signs and "test" variables. If you really need to conditionally assign variables then use "if"... but chances are good you don't need that.
b) "closure" is effectively another word
2012 Aug 27
3
How to generate a matrix of Beta or Binomial distribution
Hi folks,
I have a question about how to efficiently produce random numbers from Beta
and Binomial distributions.
For Beta distribution, suppose we have two shape vectors shape1 and shape2.
I hope to generate a 10000 x 2 matrix X whose i th rwo is a sample from
reta(2,shape1[i]mshape2[i]). Of course this can be done via loops:
for(i in 1:10000)
{
X[i,]=rbeta(2,shape1[i],shape2[i])
}
However,
2017 Jul 24
5
Ifelse statements and combining columns
Hi everyone,
I'm having some trouble with my ifelse statements.
I'm trying to put 12 conditions within 3 groups. Here is the code I have so
far:
dat$cond <- ifelse(test = dat$cond == "cond1" | dat$cond == "cond2" |
dat$cond == "cond3" dat$cond == "cond4"
yes = "Uniform"
no = ifelse(test =
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