0
0
R Programmingprogramming~10 mins

R vs Python for data analysis in R Programming - Interactive Practice

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

Complete the code to create a vector of numbers from 1 to 5 in R.

R Programming
numbers <- [1](1, 2, 3, 4, 5)
Drag options to blanks, or click blank then click option'
Ac
Bmatrix
Cdata.frame
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() creates a list, not a numeric vector.
Using data.frame() creates a data frame, which is a table-like structure.
Using matrix() creates a matrix, which is two-dimensional.
2fill in blank
medium

Complete the code to calculate the mean of a numeric vector named 'data' in R.

R Programming
average <- [1](data)
Drag options to blanks, or click blank then click option'
Amean
Bsum
Cmedian
Dmode
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() returns the total, not the average.
Using median() returns the middle value, not the average.
Using mode() is not a base R function for numeric vectors.
3fill in blank
hard

Fix the error in the code to subset rows where the 'age' column is greater than 30 in a data frame 'df'.

R Programming
subset_df <- df[df$[1] > 30, ]
Drag options to blanks, or click blank then click option'
AAge
Bage
Cage()
Dage[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Age' instead of 'age' if the column name is lowercase.
Using parentheses like 'age()' which is incorrect for column access.
Using brackets like 'age[]' which is not valid syntax here.
4fill in blank
hard

Fill both blanks to create a new data frame with only rows where 'score' is greater than 80 and select the 'name' and 'score' columns.

R Programming
high_scores <- df[df$[1] [2] 80, c('name', 'score')]
Drag options to blanks, or click blank then click option'
Ascore
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' instead of '>' for filtering scores above 80.
Using wrong column names or misspelling 'score'.
5fill in blank
hard

Fill all three blanks to create a summary table with the mean of 'height' grouped by 'gender' using the dplyr package.

R Programming
library(dplyr)
summary <- df %>% group_by([1]) %>% summarise([2] = mean([3]))
Drag options to blanks, or click blank then click option'
Agender
Bavg_height
Cheight
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names for grouping or summarising.
Not using the pipe operator %>% correctly.