Is there a way to instruct dplyr
to use summarise_each
with na.rm=TRUE
? I would like to take the mean of variables with summarise_each("mean")
but I don't know how to specify it to ignore missing values.
summarise_each: Summarise and mutate multiple columns. Apply one or more functions to one or more columns. Grouping variables are always excluded from modification.
When using a dataframe function na. rm in r refers to the logical parameter that tells the function whether or not to remove NA values from the calculation. It literally means NA remove. It is neither a function nor an operation. It is simply a parameter used by several dataframe functions.
However why did your mean return NA? When performing mathematical operations on numbers in R , most functions will return the value NA if the data you are working with include missing or nodata values. Returning NA values allows you to see that you have missing data in your dataset.
Following the links in the doc, it seems you can use funs(mean(., na.rm = TRUE))
:
library(dplyr) by_species <- iris %>% group_by(Species) by_species %>% summarise_each(funs(mean(., na.rm = TRUE)))
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