Reputation: 1
I am using this codes to import data
counts<-read.csv("data.csv", stringsAsFactors=FALSE, header=FALSE)
and to remove NAs from data I am using 2 methods
lists <- lapply(as.list(counts), function(x) x[x != ""])
removeEMPTYstrings <- function(x) {
newVectorWOstrings <- x[x != ""]
return(newVectorWOstrings)
}
lists <- lapply(as.list(counts), removeEMPTYstrings)
but both of these ways are not removing NAs from the data and I am still getting this message "Error: NAs in dataset".
I just want to remove/ignore/unread the NAs in the data and not to remove entire column or row.
Thank you.
Upvotes: 0
Views: 5234
Reputation: 887481
We can use na.omit
to remove the NA
counts1 <- na.omit(counts)
Or complete.cases
counts1 <- counts[complete.cases(counts),]
Or if we need to remove the NA by each column
lapply(counts, function(x) x[!is.na(x)])
Upvotes: 1