What function do we use to read a CSV file and what package is it from?
read_csv()
readr
Flip the card by pressing the q key.
What dplyr function do you use to chose only certain columns?
select()
What dplyr function do you use to add a new column?
mutate()
What dplyr function do you use to sort rows?
arrange()
What dplyr function do you use to keep only rows matching a condition?
filter()
df is short for Data Frame and represents the data table in the remaining cards
arrange(df, col_name_1, desc(col_name_2))
How are the rows ordered?
Ascending by col_name_1, then descending by col_name_2 within each col_name_1
How do you keep only rows where col_name_2 is "A" and col_name_1 is greater than 5?
filter(df, col_name_2 == "A", col_name_1 > 5)
Separating conditions with a comma combines them with “and”.
How do you keep rows where col_name_2 is "A" or col_name_2 is "B"?
filter(df, col_name_2 == "A" | col_name_2 == "B")
Use | to combine conditions with “or”.
What does drop_na(df) do? How is drop_na(df, col_name_1) different?
drop_na(df) removes any row with an NA in any column.
drop_na(df, col_name_1) only removes rows where col_name_1 is NA, ignoring NAs in other columns.
What does the pipe operator |> do?
It passes the result from the left side of the pipe as the first argument to the function on the right side of the pipe. This allows muliptle steps to be combined without intermediate variables.
What would this code look like using a pipe:
selected_df <- select(df, col_name_1, col_name_2)
filtered_df <- filter(selected_df, col_name_2 > 5)
filtered_df <- df |>
select(col_name_1, col_name_2) |>
filter(col_name_2 > 5)