Recall & Review
beginner
What does the $ operator do in R when working with data frames?
The $ operator extracts a column from a data frame by name, returning it as a vector.
Click to reveal answer
beginner
How do you access multiple columns from a data frame using [] in R?
Use df[, c('col1', 'col2')] to select multiple columns by name, returning a data frame.
Click to reveal answer
intermediate
What is the difference between df$col and df['col'] in R?
df$col returns the column as a vector, while df['col'] returns a data frame with one column.
Click to reveal answer
beginner
Can you use numeric indices with the [] operator to access columns in R?
Yes, df[, 2] accesses the second column of the data frame.
Click to reveal answer
intermediate
Why might you prefer df[['col']] over df$col in R?
df[['col']] allows programmatic access using a variable for the column name, while df$col requires a literal name.
Click to reveal answer
Which operator extracts a single column as a vector from a data frame in R?
✗ Incorrect
The $ operator extracts a column as a vector by name.
What does df[, c('a', 'b')] return in R?
✗ Incorrect
Using df[, c('a', 'b')] returns a data frame with those columns.
How do you access the third column of a data frame df by position?
✗ Incorrect
df[, 3] accesses the third column by numeric index.
Which method allows using a variable to select a column in R?
✗ Incorrect
df[[var]] lets you use a variable holding the column name.
What is the result type of df['col'] in R?
✗ Incorrect
df['col'] returns a data frame with one column.
Explain how to access a single column and multiple columns from a data frame in R using $ and [].
Think about how you pick one item vs several items from a list.
You got /3 concepts.
Describe the difference between df$col, df['col'], and df[[col]] in R.
Consider how each method handles the column name and output type.
You got /3 concepts.