How to set missing values in R

r
missing_values

#1

Hello,

I have a file in which missing values are coded as ?
How do I manipulate the data so that the rows with these missing values are removed??


#2

I would use gsub and use the escape character

a=c("?","?A",23,56)
> b=gsub("\\?","",a)
> b
[1] ""   "A"  "23" "56"

Note i used two \ to escape the special characters @shuvayan
:smile:


#3

thanks a lot @ajay_ohri sir :smiley:


#4

@shuvayan Also, read.table (and hence, read.csv) has an argument called na.strings to which one must assign one or more (a vector) strings which are to be considered NA values. After that’s it’s just a case of subsetting the original data-set appropriately.