Complete the code to use the switch statement to print the day name for 1.
day <- 1 result <- switch(day, [1], "Tuesday", "Wednesday") print(result)
The switch function matches the value 1 to the first option, which should be the string "Monday".
Complete the code to use switch with character input to print the correct fruit color.
fruit <- "apple" color <- switch(fruit, apple = [1], banana = "yellow", cherry = "red") print(color)
The switch matches the string "apple" and returns the color "green" as a string.
Fix the error in the switch statement to return the correct output for number 3.
num <- 3 result <- switch(num, "one", "two", [1]) print(result)
The switch statement expects string values for output. The correct string for 3 is "three".
Fill both blanks to create a switch that returns the correct day name for 2 and 4.
day <- 4 name <- switch(day, [1], [2], "Wednesday", "Thursday") print(name)
The first blank is the name for day 1: "Monday". The second blank is the name for day 2: "Tuesday".
Fill all three blanks to create a switch that returns the correct fruit color for "banana".
fruit <- "banana" color <- switch(fruit, apple = [1], banana = [2], cherry = [3]) print(color)
The switch returns "green" for apple, "yellow" for banana, and "red" for cherry.