0
0
R Programmingprogramming~20 mins

Why text processing is common in R Programming - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Text Processing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is text processing widely used in programming?

Text processing is a key part of many programs. Why is it so common?

ABecause computers can only store text and not numbers or images.
BBecause text processing does not require any memory or CPU resources.
CBecause text processing is faster than numerical calculations in all cases.
DBecause most data and communication use text formats like emails, logs, and web pages.
Attempts:
2 left
💡 Hint

Think about what kinds of information people share and store every day.

Predict Output
intermediate
2:00remaining
What is the output of this R code that processes text?

Look at this R code that counts words in a sentence. What will it print?

R Programming
sentence <- "R is great for text processing"
words <- strsplit(sentence, " ")[[1]]
length(words)
A4
B5
C6
DError: object 'strsplit' not found
Attempts:
2 left
💡 Hint

Count how many words are in the sentence after splitting by spaces.

🔧 Debug
advanced
2:00remaining
Why does this R code give an error when processing text?

Find the reason this R code fails to replace spaces with dashes in a string.

text <- "hello world"
new_text <- gsub(" ", "-", text)
print(new_text)
AMissing closing parenthesis in gsub function call.
Bgsub cannot replace spaces with dashes.
CThe variable 'text' is not defined.
Dprint function cannot print strings.
Attempts:
2 left
💡 Hint

Check the parentheses carefully in the function call.

📝 Syntax
advanced
2:00remaining
Which R code correctly extracts the first 3 characters from a string?

Choose the code that extracts the first 3 letters from the string word <- "processing".

Asubstring(word, 1, 4)
Bsubstr(word, 1, 3)
Csubstr(word, 0, 3)
Dsubstring(word, 0, 2)
Attempts:
2 left
💡 Hint

Remember R strings start at position 1, not 0.

🚀 Application
expert
2:00remaining
How many words are in this text after cleaning punctuation in R?

Given this R code, what is the number of words after removing punctuation?

text <- "Hello, world! Let's test text-processing."
clean_text <- gsub("[[:punct:]]", "", text)
words <- strsplit(clean_text, " ")[[1]]
length(words)
A5
B7
C8
D6
Attempts:
2 left
💡 Hint

Count words after punctuation is removed and text split by spaces.