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 = as.data.frame(mydata) mydata[mydata$col2== "#N/A"] <- "NA" na.omit(mydata$col2)
What can I do?
I also tried this:
mydata = mydata[!is.na(mydata)]
But it doesn't work either
You should instruct R to treat the string
NA immediately. The argument
read.csv tells R what strings to treat as
mydata <- read.csv('file:///C:/Users/file.csv', na.strings = c("", "NA", "#N/A")) mydata[complete.cases(mydata), ]