Stat Bio
Stat Bio

Reputation: 1

Removing NA from csv data file

I am using this codes to import data

counts<-read.csv("data.csv", stringsAsFactors=FALSE, header=FALSE)

link to view the data

and to remove NAs from data I am using 2 methods

1

lists <- lapply(as.list(counts), function(x) x[x != ""])

2

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

Answers (1)

akrun
akrun

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

Related Questions