I am running an is.null()
on the columns in my dataset and it returns False even though I can see NA values in my dataset. Is there a better function in R to check for null rows/entries in a column?
Asked
Active
Viewed 241 times
0

Uwe Keim
- 39,551
- 56
- 175
- 291

Prakhar Rathi
- 905
- 1
- 11
- 25
-
2to check for `NA` values use `is.na`, Eg - `is.na(df$column_name)` or `is.na(df)` where `df` is the dataframe. – Ronak Shah Mar 15 '21 at 06:38
-
1See here: https://stackoverflow.com/questions/15496361/what-is-the-difference-between-nan-and-inf-and-null-and-na-in-r – Jon Spring Mar 15 '21 at 06:41
-
@RonakShah `is.na()` is working but it's printing row-wise results. Is there a way to aggregate them for the whole column or the whole data frame? – Prakhar Rathi Mar 15 '21 at 06:53
-
It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). Do you need `colSums(is.na(df))` ? This will count number of `NA` values in each column. – Ronak Shah Mar 15 '21 at 06:56
-
@RonakShah yes, I used the sum function `sum(is.na(data$col))`. I am moving from Python to R and in Python which have functions that return a boolean value `True` if the column even has one empty value but R doesn't have something inbuilt like that but yeah it's working now. Thanks for your help! – Prakhar Rathi Mar 15 '21 at 07:06
-
1`help("anyNA")` – Roland Mar 15 '21 at 07:57
-
1For the sake of completeness, R has the `any()` function which tests if at least one element of a logical vector is TRUE. (BTW, `all()` tests if all elements are TRUE), So, `any(is.na())` should do what are asking for. However, `anyNA()` is shorter. – Uwe Mar 15 '21 at 08:59