Write a function in R language to replace the missing value in a vector with the mean of that vector?



Write a function in R language to replace the missing value in a vector with the mean of that vector..

Answer / Ankur

Here is a simple function named `fill_mean()` that replaces NA values in a vector with the mean of the non-NA values:
```R
fill_mean <- function(vector) {
if (any(is.na(vector))) {
vector[is.na(vector)] <- mean(vector, na.rm = TRUE)
}
return(vector)
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More R Programming Interview Questions

Explain the type of clustering in R?

1 Answers  


How R Commands are Written?

1 Answers  


What are R Functions?

1 Answers  


How many types of vectors are present in r?

1 Answers  


What is function definition?

1 Answers  


How many tools for debugging present in r?

1 Answers  


Explain what is pdv?

1 Answers  


What are various ways to write la oop in r?

1 Answers  


Compare R with other technologies.

1 Answers  


Why we need data visualization in R?

1 Answers  


What is the difference between rnorm and runif functions ?

1 Answers  


What is oop in r?

1 Answers  


Categories