Recall & Review
beginner
How do you select the first row of a data frame named
df in R?Use
df[1, ]. The number before the comma selects the row, and leaving the column part empty selects all columns.Click to reveal answer
beginner
What does
df[, 3] return in R?It returns the third column of the data frame
df, including all rows.Click to reveal answer
intermediate
How to select rows 2 to 4 and columns 1 and 3 from a data frame
df?Use
df[2:4, c(1, 3)]. This picks rows 2, 3, 4 and columns 1 and 3.Click to reveal answer
beginner
What happens if you use
df[ , ] in R?It returns the entire data frame
df because no rows or columns are excluded.Click to reveal answer
beginner
How to select a column by name, for example column
age, from a data frame df?Use
df["age"] or df$age. Both return the age column.Click to reveal answer
What does
df[3, ] select in R?✗ Incorrect
df[3, ] selects the third row and all columns.
How do you select the second and fourth columns of
df?✗ Incorrect
df[, c(2, 4)] selects columns 2 and 4 for all rows.
What does
df[ , ] return?✗ Incorrect
Empty row and column indices return the whole data frame.
How to select the column named
height from df?✗ Incorrect
df$height selects the column named height.
Which of these selects rows 1 to 3 and columns 2 and 4?
✗ Incorrect
df[1:3, c(2,4)] selects rows 1 to 3 and columns 2 and 4.
Explain how to select specific rows and columns from a data frame in R.
Think about how you slice a table by rows and columns.
You got /5 concepts.
Describe the difference between
df[ , 2] and df[2, ] in R.Remember the order: rows first, columns second.
You got /3 concepts.