Locate index of rows in a dataframe that have the value of NA
An alternative approach using functions from the tidyverse
ecosystem:
> dataset1 %>%
rowid_to_column() %>%
filter(is.na(x))
rowid x
1 4 NA
create newdataset1
which is a table formed after deleting rows with missing column values from dataset1
use -which(is.na)
newdataset1<-dataset1[-which(is.na(dataset1$x)),]
As suggested by Ben Bolker, you can use both which
and is.na
as in:
> which(is.na(dataset1), arr.ind=TRUE)
row col
4 4 1 # NA is in row 4 and column 1