vendredi 27 mai 2016

R-function If statement for passing on variables

Im trying to write an if statement in an a function. It's for the x variable that either can be a cuple of the variables from the dataset or all of the variables in the dataframe, 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"

I'll appreciate all the help i can get. Thanks.

Aucun commentaire:

Enregistrer un commentaire