I have a numeric column of weights (df$weight0) in a dataframe df. I want to create a new column df$weight1 which is a factor based on the values in df$weight0.
If the value in df$weight0 is less than or equal to 170, the corresponding value in df$weight1 should be 1 but if the value in df$weight0 is greater than 170,the corresponding value in df$weight1 should be 2.
The code below is what I have tried but it gives a single value not a vector.
if (i<=170){
i==1
}else{
i==2
}
}
df$weight1 <- (df$weight0>170)+1