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 |
What is Descriptive analysis in R?
Given a vector of numbers, how would you turn the values into scientific notation?
Write a custom function in R?
List the functions available in “dplyr” package?
Explain what is with () and by () function in r is used for?
What is a white noise model?
What is reference class?
How can you save your data in R?
What is r vector?
What is a factor? How would you create a factor in r?
Why the stepaic()?
What is TCP/IP in R?