Replace 0 with NA in R DataFrame
In this article, we are going to discuss how to replace 0 with NA values in dataframe in R Programming Language.
NA stands for Null values which can represent Null data / Null elements in a dataframe. The task can be achieved by first defining a dataframe that contains 0 as values. Then we can replace 0 with NA by using index operator .
dataframe[dataframe== 0] = NA
- dataframe is the input dataframe
- In index we are checking if the value is 0, if it is 0 then we are replacing it as NA
Example: Replacing 0 with NA for integer data
Example: R program to create a dataframe with strings along with 0 and replace 0 with NA