Maybe this could be useful
DF <- data.frame(VarA=letters[1:4]) # this is your data.frame
VarA
1 a
2 b
3 c
4 d
DF$VarB <- ifelse(VarA %in% c('a','c','e'), 'yes', 'no')
DF$VarC <- ifelse(VarA %in% c('a','e'), 1, ifelse(VarA %in% c('b','d'),2,3))
DF
VarA VarB VarC
1 a yes 1
2 b no 2
3 c yes 3
4 d no 2
You can use transform
function as well.
DF <- data.frame(VarA=letters[1:4])
transform(DF,
VarB=ifelse(VarA %in% c('a','c','e'), 'yes', 'no'),
VarC=ifelse(VarA %in% c('a','e'), 1, ifelse(VarA %in% c('b','d'),2,3)))
VarA VarB VarC
1 a yes 1
2 b no 2
3 c yes 3
4 d no 2