In this tutorial, we will learn how to replace all NA values in a dataframe with zero number in R programming.

To replace NA with 0 in an R dataframe, use function and then select all those values with NA and assign them to 0.

The syntax to replace NA values with 0 in R dataframe is


  • myDataframe is the dataframe in which you would like replace all NAs with 0.
  • is, na are keywords.

Example – Replace NAs with 0 in R Dataframe

In this example, we will create an R dataframe, DF1, with some of the values being NA.

Now use the function with the dataframe DF1.