📖 Scenario: You are organizing a small event and have a list of guests with their first and last names. You want to create full names by joining these names together.
🎯 Goal: Learn how to combine strings in R using paste and paste0 functions to create full names from first and last names.
📋 What You'll Learn
Create two vectors called first_names and last_names with exact values
Create a variable called separator with the exact string value " " (a space)
Use paste with first_names, last_names, and sep=separator to create full_names_with_space
Use paste0 with first_names and last_names to create full_names_no_space
Print both full_names_with_space and full_names_no_space
💡 Why This Matters
🌍 Real World
Combining first and last names is common when preparing data for invitations, reports, or user interfaces.
💼 Career
Knowing how to join strings is essential for data cleaning, report generation, and creating readable outputs in data science and programming jobs.
Progress0 / 4 steps
1
Create first and last name vectors
Create a vector called first_names with these exact values: "John", "Jane", "Alex". Also create a vector called last_names with these exact values: "Doe", "Smith", "Brown".
R Programming
Hint
Use the c() function to create vectors with the exact names.
2
Create a separator variable
Create a variable called separator and set it to the string " " (a single space).
R Programming
Hint
Assign the string with a space to the variable separator.
3
Combine names using paste and paste0
Use paste with first_names, last_names, and sep=separator to create a vector called full_names_with_space. Then use paste0 with first_names and last_names to create a vector called full_names_no_space.
R Programming
Hint
Use paste with the sep argument set to separator. Use paste0 without a separator.
4
Print the combined names
Print the vectors full_names_with_space and full_names_no_space using two separate print() statements.
R Programming
Hint
Use print() to show the vectors on the screen.
Practice
(1/5)
1. What is the main difference between paste and paste0 functions in R?
easy
A. paste adds no separator; paste0 adds spaces by default.
B. paste adds spaces by default; paste0 adds no separator.
C. paste converts numbers to characters; paste0 does not.
D. paste works only with vectors; paste0 works only with lists.
Solution
Step 1: Understand default separator in paste
paste joins strings with a space by default as separator.
Step 2: Understand default separator in paste0
paste0 joins strings without any separator (empty string).
Final Answer:
paste adds spaces by default; paste0 adds no separator. -> Option B
Quick Check:
Separator difference = paste adds spaces by default; paste0 adds no separator. [OK]