Is it possible to add an exception to summarize(count = n_distinct(x))
in R, while allowing the exception to be counted by the "normal" summarize(count = n()) function
?
How do you combine the count n()
and n_distinct()
functions to create a single new column?
This way, I could summarize the distinct count of observations in column x
, while adding an exception in the form of an observation, which would not be limited to a distinct count, but rather be subject to the "normal" summarize(count = n()) function
.
For example, if x = c(1, 2, 2, 4, 5, 8, 8, ..., 99)
, I could summarize the distinct counts of all observations except, say, the observation 8
in column x
. The observation 8
would instead be subject to the summarize(count = n()) function
. This would then count the number of 8
's plus the number of other unique values in x
.
In conclusion, this would create a single new column "count", in which all values would be from the distinct count, except for the one exception, whose value would come from the "normal" count.