I'm trying to write an if statement in a function. It's for the x variable that either can be a couple of the variables from the dataset or all of the variables in the data.frame, like: (Both X and Y are given like column names)
f <- function(y,x,data){
if (x=="all"){something<-y+2}else{something<-y+5}
}
I get the error:
"the condition has length > 1 and only the first element will be used"
ifelse(which is vectorized) instead ofif(which is not), but it's hard to say without data/context.