0
0
R Programmingprogramming~10 mins

Row and column indexing in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the first row of the data frame df.

R Programming
df[[1], ]
Drag options to blanks, or click blank then click option'
A0
Bdf
C1
Drow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as the row index (R indexing starts at 1).
Using the data frame name instead of a row number.
2fill in blank
medium

Complete the code to select the column named age from the data frame df.

R Programming
df$[1]
Drag options to blanks, or click blank then click option'
Aage
B1
Cdf
Dcolumn
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of the column name after the dollar sign.
Putting quotes around the column name after the dollar sign.
3fill in blank
hard

Fix the error in the code to select the element in the second row and third column of df.

R Programming
df[[1], 3]
Drag options to blanks, or click blank then click option'
A0
B2
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as the row index instead of 2.
Using 0 as an index (R indexing starts at 1).
4fill in blank
hard

Fill both blanks to select rows where the score column is greater than 50.

R Programming
df[df$[1] [2] 50, ]
Drag options to blanks, or click blank then click option'
Ascore
B<
C>
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name.
Using the less than operator instead of greater than.
5fill in blank
hard

Fill all three blanks to create a new data frame new_df with only the name and age columns for rows where age is less than 30.

R Programming
new_df <- df[df$[1] [2] 30, c([3])]
Drag options to blanks, or click blank then click option'
Aage
B<
C"name", "age"
D"score", "age"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong operator for comparison.
Selecting columns that are not name and age.
Not using quotes around column names inside c().