Q:

Summarising data using tidyr/dplyr functions

Below is my Data frame:
  Species   Type  Contents (kg)
1       T      f           0.0710000
2       T      f           0.1100000
3       W      f           0.0200000
4       W      f           0.0200000
5       S      f           0.2100000
6       S      f           0.2800000
7       T      w           1.1400000
8       T      w           0.6000000
9       W      w           0.5600000
10      W      w           0.5600000
11      S      w           1.9800000
12      S      w           3.1200000

Using dplyr functions I've got the mean and variance of my type f but I would also like to split the results by the species as well and was wondering how I could do this using tidyr/dplyr functions.
This is what I've used to find the mean and variance of my type f above.
summarise(group_by(Item,Type[2]),Mean = mean(Item$Contents (kg)),Variance = var(Item$Contents (kg)))

A:

Relatively simple with dplyr just call mutate
df <- read.table(text =
               " Row   Species   Type  Contents(kg)
                  1       T      f           0.0710000
                  2       T      f           0.1100000
                  3       W      f           0.0200000
                  4       W      f           0.0200000
                  5       S      f           0.2100000
                  6       S      f           0.2800000
                  7       T      w           1.1400000
                  8       T      w           0.6000000
                  9       W      w           0.5600000
                  10      W      w           0.5600000
                  11      S      w           1.9800000
                  12      S      w           3.1200000",
             header = TRUE, stringsAsFactors = FALSE)

library(dplyr)

df %>%
  group_by(Type, Species) %>%
  mutate(meanByTypeandSpecies = mean(Contents.kg.))

Results:

