I am using dplyr summarise function. My data contain NAs so I need to include na.rm=TRUE for each call. for example:
group <- rep(c('a', 'b'), 3)
value <- c(1:4, NA, NA)
df = data.frame(group, value)
library(dplyr)
group_by(df, group) %>% summarise(
mean = mean(value, na.rm=TRUE),
sd = sd(value, na.rm=TRUE),
min = min(value, na.rm=TRUE))
Is there a way to write the argument na.rm=TRUE only one time, and not on each row?
na.omit
:df %>% group_by(group) %>% na.omit() %>% summarise()
– pogibas