Home > Net >  Getting the rownumbers for all NA values of a column
Getting the rownumbers for all NA values of a column

Time:11-05

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?

CodePudding user response:

We could use which with is.na

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

CodePudding user response:

which(is.na(df$first_column)==T)
  • Related