I would like to use R to create a new column in my data frame whose elements depend on a certain condition. For example, if my element respects condition A, then the value assigned will be A. If my element respects condition B then the value assigned will be B. If my element respects condition C then the value assigned will be C.
I know how to create such a structure for two conditions with the if_else structure, which allows to say that if the element respects condition A, then it will have the value A, otherwise the value B. However, I don't know how to do this for three elements A, B, C.
Using the if, else if, else structure doesn't work because it gives me the error "Error in if (condition) { : the condition has length > 1" because I can't use vectors in condition.
Does anyone have a solution to solve this problem in the general case? Thanks a lot !