Recall & Review
beginner
What does the
select() function do in R's dplyr package?It chooses specific columns from a data frame, making it easy to work only with the data you need.
Click to reveal answer
beginner
How do you select columns
name and age from a data frame df using select()?Use
select(df, name, age) to get only those two columns.Click to reveal answer
intermediate
Can
select() use helper functions like starts_with()?Yes! You can select columns that start with a pattern, for example
select(df, starts_with('a')) picks all columns starting with 'a'.Click to reveal answer
beginner
What happens if you use
select() with a column name that does not exist?You get an error telling you the column is not found, so you need to check column names carefully.
Click to reveal answer
intermediate
How can you deselect a column using
select()?Use a minus sign before the column name, like
select(df, -age) to drop the age column.Click to reveal answer
What does
select(df, name, age) do?✗ Incorrect
select() chooses columns, so it keeps only 'name' and 'age' columns from the data frame.
How do you exclude the column 'salary' using
select()?✗ Incorrect
Using a minus sign before the column name tells select() to drop that column.
Which helper function selects columns starting with 'temp'?
✗ Incorrect
starts_with() picks columns whose names begin with the given string.
What will happen if you try
select(df, unknown_column)?✗ Incorrect
select() requires existing columns; unknown columns cause an error.
Which of these is a correct way to select columns 'x' and 'y'?
✗ Incorrect
select() takes column names as separate arguments.
Explain how to use
select() to pick specific columns from a data frame.Think about how you tell R which columns you want to keep.
You got /3 concepts.
Describe how to exclude columns using
select() and how helper functions can help select columns by pattern.Remember you can both pick and drop columns easily.
You got /3 concepts.