mardi 16 avril 2019

What is the best way to put if statement in following two scenarios in R? and what is the difference?

What is the best way to put if statement in following two scenarios in R? both answers are same and correct.

Scenario 1

    pow_one <- function(x,print_info = TRUE) {
    y <- x ^ 2
    if(print_info){
      print(paste(x, "to the power two equals", y))
      }
      return(y)

    }

Scenario 2

pow_two <- function(x,print_info = TRUE) {
if(print_info){
  y <- x ^ 2
  print(paste(x, "to the power two equals", y))
  return(y)
  }
}

Aucun commentaire:

Enregistrer un commentaire