Getting the rownumbers for all NA values of a column

I have data as follows:

df <- as.data.frame(c(1,2,NA,4,5))
names(df)[1] <- "first_column"

  first_column
1            1
2            2
3           NA
4            4
5            5

I would like to get all the row numbers for which first_column is NA, so 3

I found ways to look up other values, i.e. which(grepl(2, df$first_column))
but not NA. Including NA values is apparently quite cumbersome (link).
Is there an easier way to do this?

Any ideas?

>Solution :

We could use which with is.na

which(is.na(df))
[1] 3

Leave a Reply