Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The $ operator is used in R to access columns by name in a data frame.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
Double square brackets [[ ]] are used to extract a single column as a vector by name.
3fill in blank
hardFix 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'
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 [[ ].
✗ Incorrect
Using [["score"]] extracts the column as a vector, which is the correct way here.
4fill in blank
hardComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ inside brackets which is invalid syntax.
Using 1 instead of the column name string.
✗ Incorrect
Using [ , "height"] selects the 'height' column as a data frame subset.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ with quotes which is invalid syntax.
Forgetting to close the brackets.
✗ Incorrect
Double brackets [["weight"]] extract the 'weight' column as a vector.