0
0
R Programmingprogramming~20 mins

paste and paste0 in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Paste Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of paste with default separator
What is the output of this R code snippet?
R Programming
result <- paste("apple", "banana", "cherry")
print(result)
A[1] "apple banana cherry"
B[1] "apple,banana,cherry"
C[1] "apple-banana-cherry"
D[1] "applebananacherry"
Attempts:
2 left
💡 Hint
Remember that paste uses a space as the default separator.
Predict Output
intermediate
2:00remaining
Output of paste0 with multiple strings
What does this R code print?
R Programming
result <- paste0("red", "green", "blue")
print(result)
A[1] "redgreenblue"
B[1] "red,green,blue"
C[1] "red-green-blue"
D[1] "red green blue"
Attempts:
2 left
💡 Hint
paste0 joins strings without any separator.
🧠 Conceptual
advanced
2:00remaining
Difference between paste and paste0
Which statement correctly describes the difference between paste() and paste0() in R?
Apaste() joins strings with no separator; paste0() joins strings with a space by default.
Bpaste() and paste0() both join strings with a comma separator by default.
Cpaste() joins strings with a space by default; paste0() joins strings with no separator.
Dpaste() joins strings with a dash by default; paste0() joins strings with an underscore.
Attempts:
2 left
💡 Hint
Think about the default separator each function uses.
Predict Output
advanced
2:00remaining
Output of paste with custom separator
What is the output of this R code?
R Programming
result <- paste("cat", "dog", "mouse", sep = "-")
print(result)
A[1] "catdogmouse"
B[1] "cat dog mouse"
C[1] "cat,dog,mouse"
D[1] "cat-dog-mouse"
Attempts:
2 left
💡 Hint
Look at the sep argument value.
Predict Output
expert
2:00remaining
Output of paste with recycling and paste0
What is the output of this R code?
R Programming
x <- c("a", "b")
y <- c(1, 2, 3)
result <- paste0(x, y)
print(result)
A[1] "a1" "a2" "a3"
B[1] "a1" "b2" "a3"
C[1] "a1" "b2" "b3"
D[1] "a1" "b2" "c3"
Attempts:
2 left
💡 Hint
Remember how R recycles shorter vectors to match longer ones.