I want to summarize and apply a function to variables which are either numeric or factor. In other words, I want to leave out of the "summarize" character variables.
Is there a way to either: a) summarize all variables that are NOT characters (i.e. my intuition tried summarize_if(!is.character, ...), or b) add multiple conditions to summarize_if, to apply the summary to both numeric and factor variables - e.g. something like summarize_if(is.numeric | is.factor, ...)?
PD: I am doing group_by and summarize_if to collapse observations based on their id. I know there are other methods to do so, but the dataset has ~700k observations, I want to apply this formula to approximately 20 variables, and other methods I've tried are very slow.
This is the code I was trying without success:
data %>%
group_by(id_variable) %>%
summarize_if(vars(!is.character), ~.[!is.na(.)][1L])