Complete the code to check if x is equal to 10.
x <- 10 result <- x [1] 10 print(result)
In R, == is used to compare if two values are equal.
Complete the code to check if y is greater than 5.
y <- 7 if (y [1] 5) { print("y is greater than 5") }
The operator > checks if the left value is greater than the right value.
Fix the error in the code to check if z is not equal to 0.
z <- 3 if (z [1] 0) { print("z is not zero") }
The operator != means 'not equal to' in R.
Complete the code to create a dictionary of words and their lengths, but only for words longer than 3 letters.
words <- c("cat", "house", "dog", "elephant") lengths <- list() for (word in words) { if (nchar(word) [1] 3) { lengths[[word]] <- nchar(word) } }
The condition nchar(word) > 3 selects words longer than 3 letters. The {{BLANK_2}} is empty because we just assign the length.
Fill both blanks to create a named list of uppercase words and their lengths, only if length is at least 4.
words <- c("tree", "sun", "flower", "sky") result <- list() for (w in words) { if (nchar(w) [1] 3) { result[[[2]]] <- nchar(w) } }
The condition nchar(w) > 3 filters words with length at least 4. The name uses toupper(w) to uppercase the word. No operator is needed when assigning the length.