How can I assign a value using if-else conditions in R

You can use ifelse to act on vectors with if statements.

ifelse(a>=10, "double", "single")

So your code could look like this

mydata <- cbind(a, ifelse(a>10, "double", "single"))

(Specified in comments below that if a=10, then “double”)

Leave a Comment