Recall & Review
beginner
What does the
mutate() function do in R's dplyr package?mutate() adds new columns or changes existing ones in a data frame without removing existing data.
Click to reveal answer
beginner
How do you create a new column
total as the sum of columns price and tax using mutate()?df %>% mutate(total = price + tax)
Click to reveal answer
beginner
Can
mutate() use existing columns to create new ones?Yes, mutate() can use existing columns to calculate values for new columns.
Click to reveal answer
intermediate
What happens if you use
mutate() to create a column with the same name as an existing one?The existing column is replaced by the new values you provide.
Click to reveal answer
beginner
Write a
mutate() example that creates a new column discounted_price which is 10% less than price.df %>% mutate(discounted_price = price * 0.9)
Click to reveal answer
What is the main purpose of
mutate() in dplyr?✗ Incorrect
mutate() is used to add new columns or change existing ones.
Which of the following creates a new column
area as length * width using mutate()?✗ Incorrect
Multiplying length and width inside mutate() creates the new column area.
If you want to replace an existing column
score with its square, which is correct?✗ Incorrect
Using the same column name in mutate() overwrites it.
Can
mutate() create multiple new columns at once?✗ Incorrect
You can add many new columns in one mutate() call by separating them with commas.
What will this code do?
df %>% mutate(new_col = NA)✗ Incorrect
This creates a new column with all values set to missing (NA).
Explain how to use
mutate() to add a new column based on existing columns in a data frame.Think about how you create a new column that depends on others.
You got /4 concepts.
Describe what happens if you use
mutate() to create a column with the same name as an existing one.Consider how mutate handles column names.
You got /4 concepts.