Complete the code to check if the string contains the word 'cat'.
grepl([1], "The cat is sleeping")
The grepl function checks if the pattern "cat" is found in the string.
Complete the code to extract all words starting with 'b' from the string.
regmatches(text, gregexpr([1], text))The pattern "\bb\w+" matches words starting with 'b'.
Fix the error in the pattern to match email addresses.
grepl([1], email)In R strings, a single backslash must be escaped with another backslash. So to match a literal dot, use \\. in the regex, which becomes \. in the string. Option C correctly escapes it.
Fill both blanks to create a named vector with word lengths for words longer than 3 letters.
word_lengths <- c([1] = nchar([2]))
The c() function creates a named vector. The name is each word and the value is the length of each words element.
Fill all three blanks to create a list of words longer than 4 letters with their uppercase versions.
result <- list([1] = [2], [3] = toupper([2]))
The list has two elements: long_words holding the words, and long_words holding their uppercase forms. The variable holding the words is words.