I'd like to make a conditional 0/1 variable in my dataset, based on the value of another variable. My Ifeslse statements aren't working
If Repeat > 3, then fast = 0
If Repeat < 3, then fast = 1
I'm getting the correct output, in the form as "TRUE" "FALSE" in my bottom readout box, but the values in my data set aren't changing
I've tried my "Repeat" variable as numeric and as a factor
as.factor(dat1$Repeat)
f.s = 1
numb.repeat$f.s = 1
as.numeric(numb.repeat$f.s)
ifelse(numb.repeat$Repeat > 3, numb.repeat$f.s == 0, numb.repeat$f.s ==1)
The column you want to assign using ifelse
should appear on the LHS (left hand side) of the ifelse
expression:
numb.repeat$f.s <- ifelse(numb.repeat$Repeat > 3, 0, 1)
But actually, you don't even need ifelse
here:
numb.repeat$f.s <- numb.repeat$Repeat <= 3