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 summaris
I don't know if my answer will add something to the previous comments. Hopefully yes.
In my case, I had a database from an experiment with two groups (control, exp) with different levels for a specific variable (day) and I wanted to get a summary of mean and sd of another variable (weight) for each group for specific levels of the variable day.
Here is an example of my database:
animal group day weight 1.1 "control" 73 NA 1.2 "control" 73 NA 3.1 "control" 73 NA 9.2 "control" 73 25.2 9.3 "control" 73 23.4 9.4 "control" 73 25.8 2.1 "exp" 73 NA 2.2 "exp" 73 NA 10.1 "exp" 73 24.4 10.2 "exp" 73 NA 10.3 "exp" 73 24.6
So, for instance, in this case I wanted to get the mean and sd of the weight on day 73 for each of the groups (control, exp), omitting the NAs.
I did this with this command:
data[data$day=="73",] %>% group_by(group) %>% summarise(mean(weight[group == "exp"], na.rm=T),sd(weight[group == "exp"], na.rm=T))
data[data$day=="73",] %>% group_by(group) %>% summarise(mean(weight[group == "control"], na.rm=T),sd(weight[group == "control"], na.rm=T))