I made these questions based on the Analyzing Patient Data lesson from the R programming lessons.
Question 1
Suppose you had a dataframe named df
:
A | B | C | D | E |
---|---|---|---|---|
02 | 66 | 04 | 94 | 12 |
78 | 97 | 05 | 44 | 71 |
92 | 32 | 55 | 17 | 73 |
18 | 82 | 96 | 01 | 38 |
49 | 25 | 15 | 80 | 02 |
How could I ask R to return the 3rd and 5th rows of the dataframe?
df[3,5]
df[c(3,5)]
df(c(3,5),)
df[c(3,5),]
Question 2
With the same dataframe as above, what would the following code produce?
max(df[2:4, c(1,4)])
- 92
- 96
- 78
- 97
Misconceptions
- Correct answer
- They have switched rows and columns
- Not understood that
2:4
means rows 2, 3, and 4 (not just 2 and 4) - Not understood that
c(1,4
is different from1:4