0
0
R Programmingprogramming~5 mins

select() for column selection in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARenames columns 'name' and 'age'
BDeletes columns 'name' and 'age' from df
CFilters rows where name and age are present
DSelects only the columns 'name' and 'age' from df
How do you exclude the column 'salary' using select()?
Aselect(df, salary)
Bselect(df, -salary)
Cselect(df, exclude(salary))
Dselect(df, drop(salary))
Which helper function selects columns starting with 'temp'?
Acontains('temp')
Bends_with('temp')
Cstarts_with('temp')
Dmatches('temp')
What will happen if you try select(df, unknown_column)?
AThrows an error about missing column
BReturns an empty data frame
CReturns all columns
DAutomatically creates the column
Which of these is a correct way to select columns 'x' and 'y'?
Aselect(df, x, y)
Bselect(df, c('x', 'y'))
Cselect(df, ['x', 'y'])
Dselect(df, x & y)
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.