Write a function to replace NA values in a vector with the median of the non-NA values.
MediumProblem Statement
Write a function to replace NA values in a vector with the median of the non-NA values.
Sample Input
Vector: c(10, 20, NA, 40, 50)
Sample Output
Replaced Vector: 10 20 30 40 50
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
replace_na_with_median <- function(vector) {
# Your logic here
}
result <- replace_na_with_median(vector)
print(paste("Replaced Vector:", result))
Input
Vector: c(10, 20, NA, 40, 50)
Expected Output
Replaced Vector: 10 20 30 40 50