why do function and conditional statements give wrong output?

Give this a try. I changed “sex” to “x” so you don’t just return the string you used as input for the function.. I’ve also added some spaces to help with legibility.

salutation <- function(sex, name){if (sex == "M"){x <- "Mr."} 
  else {if (sex == "F"){x <- "Ms."}}
   {paste0("Greetings ", x," ", name,", How are you today?")}


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top