0
0
R Programmingprogramming~10 mins

Handling missing values (na.rm, na.omit) 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 calculate the mean of the vector, ignoring missing values.

R Programming
mean(c(1, 2, NA, 4), [1] = TRUE)
Drag options to blanks, or click blank then click option'
Ana.rm
Bna.omit
Cremove.na
DskipNA
Attempts:
3 left
💡 Hint
Common Mistakes
Using na.omit inside mean() instead of na.rm
Misspelling the argument name
Setting na.rm to FALSE
2fill in blank
medium

Complete the code to remove missing values from the vector using a function.

R Programming
clean_vector <- [1](c(3, NA, 5, NA, 7))
Drag options to blanks, or click blank then click option'
Ana.rm
Bna.omit
CremoveNA
DdropNA
Attempts:
3 left
💡 Hint
Common Mistakes
Using na.rm as a function instead of an argument
Using incorrect function names like removeNA
Trying to subset manually without na.omit
3fill in blank
hard

Fix the error in the code to calculate the sum ignoring missing values.

R Programming
sum_values <- sum(c(10, NA, 20), [1] = TRUE)
Drag options to blanks, or click blank then click option'
Ana.rm
Bna.omit
CremoveNA
DskipNA
Attempts:
3 left
💡 Hint
Common Mistakes
Using na.omit as an argument instead of na.rm
Misspelling the argument name
Not setting the argument to TRUE
4fill in blank
hard

Fill both blanks to create a named vector with lengths of words longer than 3 characters.

R Programming
lengths <- {word: [1] for word in words if nchar(word) [2] 3}
Drag options to blanks, or click blank then click option'
Anchar(word)
B>
C<
Dlength(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() instead of nchar() for strings
Using < instead of > for filtering
Not filtering words at all
5fill in blank
hard

Fill all three blanks to create a named vector of word lengths for words longer than 4 characters.

R Programming
result <- list([1]: [2] for [3] in words if nchar([3]) > 4)
Drag options to blanks, or click blank then click option'
Aword
Bnchar(word)
Dlength(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Using length() instead of nchar() for strings
Not filtering words longer than 4 characters