Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I have a data frame where one column is a character data type. Some values are having "\N" written in that column and I want to eliminate the rows containing those values from the data frame. I could not figure it out The current code what I am using is : 

airports_m<-airports_m[airports_m$IATA != "\N",] 

This gives the error

Error: '\N' is an unrecognized escape in character string starting ""\N"

1 Answer

0 votes
by (107k points)

See the backslashes are 'escape' characters in R strings. Say for instance, linefeeds are "\n" and tabs are "\t". So to have a real backslash you have to escape the escape character. To indicate the two-character string \N use the string "\\N". So to your code,

library(tidyverse)

airports_m %>%

  filter(IATA != "\\N")

Or just in case there's some other trash on the line

airports_m %>%

  filter(! str_detect(IATA , "\\N"))

If you are a beginner and want to know more about R then do check out the R programming course

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...