Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any ideas?

>Solution :

We could use which with is.na

which(is.na(df))
[1] 3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading