Remove rows with missing values in R [duplicate]

I want to remove all rows with NAs, I tried na.omit, but I still have all the "#N/A" values in my data...

This is my code:

mydata = read.csv('file:///C:/Users/file.csv')
mydata =
mydata[mydata$col2== "#N/A"] <- "NA"

What can I do?

I also tried this:

mydata = mydata[!]

But it doesn't work either


You should instruct R to treat the string #N/A as NA immediately. The argument na.strings to read.csv tells R what strings to treat as NA.

mydata <- read.csv('file:///C:/Users/file.csv', na.strings = c("", "NA", "#N/A"))
mydata[complete.cases(mydata), ]