0
0
R Programmingprogramming~10 mins

Handling missing values (drop_na, fill) 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 remove rows with missing values from the data frame.

R Programming
clean_data <- [1](data)
Drag options to blanks, or click blank then click option'
Adrop_na
Bfill_na
Cna.omit
Dreplace_na
Attempts:
3 left
💡 Hint
Common Mistakes
Using fill_na which is not a function to drop rows.
Using na.omit which works but is base R, not tidyverse.
2fill in blank
medium

Complete the code to replace missing values in the 'score' column with 0.

R Programming
data$score <- [1](data$score, 0)
Drag options to blanks, or click blank then click option'
Afill_na
Breplace_na
Cdrop_na
Dna.omit
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop_na which removes rows instead of replacing values.
Using fill_na which is not a base or tidyverse function.
3fill in blank
hard

Fix the error in the code to fill missing values in the 'age' column with the previous non-missing value.

R Programming
library(tidyr)
data <- [1](data, age, .direction = "down")
Drag options to blanks, or click blank then click option'
Areplace_na
Bdrop_na
Cna.locf
Dfill
Attempts:
3 left
💡 Hint
Common Mistakes
Using replace_na which replaces with a fixed value, not previous values.
Using drop_na which removes rows instead of filling.
4fill in blank
hard

Fill both blanks to create a new data frame without missing values and then replace missing values in 'height' with 170.

R Programming
clean_data <- data %>% [1]() %>% mutate(height = [2](height, 170))
Drag options to blanks, or click blank then click option'
Adrop_na
Breplace_na
Cfill
Dna.omit
Attempts:
3 left
💡 Hint
Common Mistakes
Using fill() instead of replace_na() to replace values.
Using na.omit inside the pipe which is less common.
5fill in blank
hard

Fill all three blanks to create a dictionary of counts for non-missing 'category' values, filtering out categories with zero count.

R Programming
counts <- table(data$category) %>% as.data.frame() %>% filter(Freq [1] 0) %>% mutate(category = as.character([2]), count = [3])
Drag options to blanks, or click blank then click option'
A>
BVar1
CFreq
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in filter condition.
Mixing up column names in mutate.