samedi 7 mars 2015

multiple execution when using ifelse


my code:
s<-function(v,k){
ifelse(k>length(v),print("error,k>length(v)"),return(v-k))
}
v=1:5
k=6
s(v,k)


output:



> s(v,k)
[1] "error,k>length(v)"
[1] "error,k>length(v)"




  1. Why is this printing twice? thanks




  2. Is there some kind of error handler I could use here?




Aucun commentaire:

Enregistrer un commentaire