Complete the code to print the value of x inline.
x <- 5 cat("The value of x is ", [1], "\n")
The variable x holds the value 5, so using x inline prints its value.
Complete the code to embed the result of 3 + 4 inline in the string.
cat(sprintf("3 + 4 equals %d\n", [1]))
Using 3 + 4 inside sprintf evaluates the expression and inserts the result.
Fix the error in the code to correctly embed the variable y inline.
y <- 10 cat(paste0("Value of y is ", [1]))
Using as.character(y) converts the number to a string so it can be concatenated inside paste0.
Fill both blanks to create a named list with word lengths greater than 3.
words <- c("cat", "house", "dog", "elephant") lengths <- list() for (word in words) { if (nchar(word) [1] 3) { lengths[[word]] <- [2] } }
The condition checks if the word length is greater than 3, and then stores the length using nchar(word).
Fill all three blanks to create a named vector with uppercase keys and values for words longer than 4.
words <- c("apple", "bat", "carrot", "dog") result <- c() for (w in words) { if (nchar(w) [1] 4) { result[[2]] <- [3] } }
The condition checks if the word length is greater than 4. The key is the uppercase word using toupper(w), and the value is the original word w.