0
0
R Programmingprogramming~10 mins

Accessing columns ($, []) 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 access the 'age' column using the $ operator.

R Programming
ages <- data[1]age
Drag options to blanks, or click blank then click option'
A@
B[[
C[
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using [ or [[ instead of $ when the task asks for $ operator.
Using @ which is for S4 objects, not data frames.
2fill in blank
medium

Complete the code to access the 'name' column using double square brackets.

R Programming
names <- data[1]"name"]
Drag options to blanks, or click blank then click option'
A[[
B$
C[
D@
Attempts:
3 left
💡 Hint
Common Mistakes
Using single brackets [ which return a data frame, not a vector.
Using $ which is correct but not what the question asks.
3fill in blank
hard

Fix the error in accessing the 'score' column as a vector.

R Programming
scores <- data[1]"score"]
Drag options to blanks, or click blank then click option'
A[[
B$
C[
D@
Attempts:
3 left
💡 Hint
Common Mistakes
Using single brackets [ which returns a data frame, causing errors if vector expected.
Using $ which works but the syntax here expects [[ ].
4fill in blank
hard

Complete the code to create a subset data frame with only the 'height' column.

R Programming
subset <- data[ , [1]]
Drag options to blanks, or click blank then click option'
A[
B$
C"height"
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ inside brackets which is invalid syntax.
Using 1 instead of the column name string.
5fill in blank
hard

Fill both blanks to extract the 'weight' column as a vector from the data frame.

R Programming
weights <- data[1][2]weight
Drag options to blanks, or click blank then click option'
A[[
B"
C]
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ with quotes which is invalid syntax.
Forgetting to close the brackets.