0
0
R Programmingprogramming~10 mins

Why data frames are central to R in R Programming - Test Your Understanding

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

Complete the code to create a data frame with columns 'Name' and 'Age'.

R Programming
df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, [1]))
Drag options to blanks, or click blank then click option'
Ac(30)
B"30"
C30
DAge
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes makes them strings, which is not correct here.
2fill in blank
medium

Complete the code to access the 'Age' column from the data frame 'df'.

R Programming
ages <- df$[1]
Drag options to blanks, or click blank then click option'
AAge
B"Age"
Cage
DAGE
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes inside the $ operator causes an error.
Using wrong case for the column name.
3fill in blank
hard

Fix the error in the code to add a new column 'Salary' with values 50000 and 60000.

R Programming
df$Salary <- c(50000, [1])
Drag options to blanks, or click blank then click option'
A60000L
B60000
C"60000"
Dc(60000)
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes makes the value a string.
Using c(60000) inside c() creates a nested vector.
4fill in blank
hard

Fill both blanks to filter rows where Age is greater than 25 and select the 'Name' column.

R Programming
subset_df <- df[df$[1] [2] 25, "Name"]
Drag options to blanks, or click blank then click option'
AAge
B>
C<
DSalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name for filtering.
Using the wrong comparison operator.
5fill in blank
hard

Fill all three blanks to create a summary data frame with mean Age and mean Salary.

R Programming
summary_df <- data.frame(MeanAge = mean(df$[1]), MeanSalary = mean(df$[2]), Count = nrow(df[3]))
Drag options to blanks, or click blank then click option'
AAge
BSalary
C[, ]
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names.
Forgetting parentheses after nrow.