VOOZH about

URL: https://www.geeksforgeeks.org/r-language/replace-character-value-with-na-in-r/

⇱ Replace Character Value with NA in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Replace Character Value with NA in R

Last Updated : 29 Sep, 2021

In this article, we are going to see how to replace character value with NA in R Programming Language.

We can replace a character value with NA in a vector and in a dataframe.

Example 1: Replace Character Value with NA in vector

In a vector, we can replace it by using the indexing operation.

Syntax:

vector[vector == "character"] <- NA 

Output:

 [1] "a" "d" "A" "g" NA NA "t" NA "e" NA

Example 2: Replace Character Value with NA in Dataframe

Replace character value with NA in dataframe.

Syntax:

dataframe[dataframe== "character"] <- NA

Output:

 X.a. X.d. X.A. X.g. X.S. X.S..1 X.t. X.S..2 X.e. X.S..3
1 a d <NA> g S S t S e S
Comment

Explore