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 |
Explain the type of clustering in R?
How R Commands are Written?
What are R Functions?
How many types of vectors are present in r?
What is function definition?
How many tools for debugging present in r?
Explain what is pdv?
What are various ways to write la oop in r?
Compare R with other technologies.
Why we need data visualization in R?
What is the difference between rnorm and runif functions ?
What is oop in r?