0
0
R Programmingprogramming~20 mins

Character (string) type in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
R String Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this R code?
Consider the following R code snippet. What will it print?
R Programming
text <- "Hello, R!"
cat(substr(text, 8, 9))
AR!
BR
CR!\n
Dlo
Attempts:
2 left
💡 Hint
Remember that substr extracts characters from start to end positions inclusive.
Predict Output
intermediate
2:00remaining
What does this R code print?
What is the output of this R code?
R Programming
text <- "Data123"
print(grepl("[0-9]", text))
ATRUE
BFALSE
CError: invalid regular expression
DNA
Attempts:
2 left
💡 Hint
grepl returns TRUE if the pattern is found anywhere in the string.
🔧 Debug
advanced
2:00remaining
Why does this R code produce an error?
This code is intended to concatenate two strings with a space. Why does it produce an error?
R Programming
str1 <- "Hello"
str2 <- 123
result <- paste(str1, str2, sep=" ")
print(result)
AError because sep argument is invalid
BNo error; output is "Hello 123"
CError because str2 is numeric and paste requires strings
DError because print cannot print numeric values
Attempts:
2 left
💡 Hint
Check how paste handles numeric arguments.
Predict Output
advanced
2:00remaining
What is the output of this R code involving string splitting?
What does this R code print?
R Programming
text <- "apple,banana,carrot"
result <- strsplit(text, ",")[[1]]
print(length(result))
A0
B1
CError: subscript out of bounds
D3
Attempts:
2 left
💡 Hint
strsplit returns a list; extracting the first element gives the vector of split strings.
🧠 Conceptual
expert
2:00remaining
Which option correctly explains the behavior of R's character vectors?
Which statement about character vectors in R is TRUE?
ACharacter vectors automatically convert numbers to strings when combined.
BCharacter vectors store strings as linked lists internally.
CCharacter vectors are immutable; you cannot change individual characters inside a string element.
DCharacter vectors can contain elements of different types like numbers and strings.
Attempts:
2 left
💡 Hint
Think about how strings behave in R when you try to change a single character.