mercredi 2 mars 2016

Why statement ifelse(i == 1,print("yes!"),print("no.")) in R print "no." twice?

When i use R in Rstudio Console, i confronted some confusions:

i <- 0
ifelse(i == 1,print("yes!"),print("no."))
## [1] "no."
## [1] "no."

but when i try non-function, it will print only once:

i <- 0
ifelse(i == 1, i + 1, i + 2)
## [1] 2 

Why Rstudio print twice instead of once in upper situation? What's the difference ?

Aucun commentaire:

Enregistrer un commentaire