EDIT: The accepted answer has helped the scales fall from my eyes; this change is an improvement and not annoying after all.
In the help file for table
, it is now written:
Non-factor arguments a are coerced via factor(a, exclude=exclude). Since R 3.4.0, care is taken not to count the excluded values (where they were included in the NA count, previously).
This is annoying. Before, you could call table(x, exclude = NULL)
and get explicit confirmation of the number of NA
values. Now, if there are none, you aren't told. Observe:
vec_with_no_nas <- c("A", "B", "B", "C")
vec_with_nas <- c("A", "B", NA, "C")
table(vec_with_no_nas)
table(vec_with_no_nas, exclude = NULL)
table(vec_with_nas)
table(vec_with_nas, exclude = NULL)
This gives output:
> table(vec_with_no_nas)
vec_with_no_nas
A B C
1 2 1
> table(vec_with_no_nas, exclude = NULL)
vec_with_no_nas
A B C
1 2 1
See? no explicit confirmation of zero NAs.
What I really want is something like the old behavior, which was:
> table(vec_with_no_nas, exclude = NULL)
vec_with_no_nas
A B C <NA>
1 2 1 0
FWIW, if the vector does have NA values, table(x, exclude = NULL)
will tell you:
> table(vec_with_nas)
vec_with_nas
A B C
1 1 1
> table(vec_with_nas, exclude = NULL)
vec_with_nas
A B C <NA>
1 1 1 1
I work in base and in the tidyverse
. Is there a drop-in table
replacement that will do explicit confirmation of no NAs?