Is there a way to instruct dplyr
to use summarise_each
with specification first
and na.rm=TRUE
?
I have a dataframe with many NAs and numeric values. Column A is patient ID. I would like to summarise the dataframe according to patient ID by taking the first non-NA of each variables. This didn't work
`summarised_df <- df %>% group_by(patient_ID) %>%
summarise_each(funs(first(., na.rm=TRUE)))`
Thanks in advance!
Here you can find an example of the data. However, the original data includes hundreds of different variables.
You can use first(na.omit(.))
or na.omit(.)[1]
. Besides summarise_each
is deprecated, use summarise_all
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With