0
0
R Programmingprogramming~5 mins

Row and column indexing in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe third row with all columns
BThe third column with all rows
CThe third row and third column
DAll rows and third column
How do you select the second and fourth columns of df?
Adf[2:4, ]
Bdf[c(2, 4), ]
Cdf[, c(2, 4)]
Ddf[c(2, 4)]
What does df[ , ] return?
AAn error
BThe entire data frame
COnly the first row
DOnly the first column
How to select the column named height from df?
Adf$height
Bdf[height]
Cdf[, height]
Ddf[height, ]
Which of these selects rows 1 to 3 and columns 2 and 4?
Adf[2:4, c(1,3)]
Bdf[c(1,3), 2:4]
Cdf[c(2,4), 1:3]
Ddf[1:3, c(2,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.