How to remove NA values from a Vector in R

445    Asked by NatashaKadam in Java , Asked on Jul 26, 2021

 Is there any way to remove NA values from a vector? If we have a vector consisting of lot values with NA values, how to remove it? Suppose I have to sum the vector without including NA values?

Answered by Lauren Hardacre
    To calculate sum we can use "sum()" Func by passing argument "na.rm=TRUE"
x<-c(1,23,45,NA,155,78,NA)
sum(x,na.rm=TRUE)
to remove NA value in r from the vector
x<-x[!is.na(x)]

The na. omit() function returns a list without any rows that contain na values. This is the fastest way to remove na rows in the R programming language. Passing your data frame or matrix through the na.



Your Answer

Interviews

Parent Categories