How to Replace NA values with Column Mean
impute with mean values
replace NA
One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called imputation. In th…
Create a Matrix/Dataframe with NAs
Let us use sample() function to create some data with missing values - NAs.
set.seed(2020)
data [How to Replace NAs with Column mean using tidyverse](https://rstats101.com/replace-nas-with-column_mean-using-tidyverse/)
Have not timed it, but for much larger dataframes, tidyverse approach might be slower than the base R approach.
## Related Tutorials
- [Simple Barpots and reordering bars in R](barpots-and-reordering-bars-in-r.html)
- [How to Compute Compound Interest with Tidyverse](calculate-compound-interest.html)
- [How to Convert a List to a dataframe in R](convert-a-list-to-a-dataframe-in-r.html)
- [ls() in R: list objects/variables in your environment](ls-list-objects-in-environment.html)
- [List of Built in Datasets in R](built-in-datasets-in-r.html)
:::{#quarto-navigation-envelope .hidden}
[Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1zaWRlYmFyLXRpdGxl"}
[Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXItdGl0bGU="}
[Home]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6SG9tZQ=="}
[/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2luZGV4Lmh0bWw="}
[LLM]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6TExN"}
[/llm/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2xsbS9pbmRleC5odG1s"}
[dplyr]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6ZHBseXI="}
[/dplyr/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2RwbHlyL2luZGV4Lmh0bWw="}
[tidyr]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6dGlkeXI="}
[/tidyr/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L3RpZHlyL2luZGV4Lmh0bWw="}
[ggplot2]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6Z2dwbG90Mg=="}
[/ggplot2/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2dncGxvdDIvaW5kZXguaHRtbA=="}
[Statistics]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6U3RhdGlzdGljcw=="}
[/statistics/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L3N0YXRpc3RpY3MvaW5kZXguaHRtbA=="}
[How-To]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6SG93LVRv"}
[/how-to/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2hvdy10by9pbmRleC5odG1s"}
[Base R]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6QmFzZSBS"}
[/base-r/index.html]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLWludC1uYXZiYXI6L2Jhc2Utci9pbmRleC5odG1s"}
:::{.hidden .quarto-markdown-envelope-contents render-id="Zm9vdGVyLWxlZnQ="}
Copyright 2025 Rstats101. All rights reserved.
:::
:::{.hidden .quarto-markdown-envelope-contents render-id="Zm9vdGVyLXJpZ2h0LS9hYm91dC5odG1s"}
About
:::
:::{.hidden .quarto-markdown-envelope-contents render-id="Zm9vdGVyLXJpZ2h0LS9wcml2YWN5Lmh0bWw="}
Privacy Policy
:::
:::
:::{#quarto-meta-markdown .hidden}
[How to Replace NA values with Column Mean – Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLW1ldGF0aXRsZQ=="}
[How to Replace NA values with Column Mean – Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLXR3aXR0ZXJjYXJkdGl0bGU="}
[How to Replace NA values with Column Mean – Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLW9nY2FyZHRpdGxl"}
[Rstats 101]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLW1ldGFzaXRlbmFtZQ=="}
[One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called imputation. In th...]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLXR3aXR0ZXJjYXJkZGVzYw=="}
[One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called imputation. In th...]{.hidden .quarto-markdown-envelope-contents render-id="cXVhcnRvLW9nY2FyZGRkZXNj"}
:::
<!-- -->
::: {.quarto-embedded-source-code}
```````````````````{.markdown shortcodes="false"}
---
title: "How to Replace NA values with Column Mean"
description: "One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called imputation. In th..."
date: 2022-01-14
categories: ['impute with mean values', 'replace NA']
format:
html:
code-fold: false
code-tools: true
---
### Create a Matrix/Dataframe with NAs
Let us use sample() function to create some data with missing values - NAs.
```r
set.seed(2020)
data [How to Replace NAs with Column mean using tidyverse](https://rstats101.com/replace-nas-with-column_mean-using-tidyverse/)
Have not timed it, but for much larger dataframes, tidyverse approach might be slower than the base R approach.
## Related Tutorials
- [Simple Barpots and reordering bars in R](barpots-and-reordering-bars-in-r.html)
- [How to Compute Compound Interest with Tidyverse](calculate-compound-interest.html)
- [How to Convert a List to a dataframe in R](convert-a-list-to-a-dataframe-in-r.html)
- [ls() in R: list objects/variables in your environment](ls-list-objects-in-environment.html)
- [List of Built in Datasets in R](built-in-datasets-in-r.html):::