I am looking for help to work out how to re-arrange my dataset.
I have a dataset the looks a bit like this called data:
No | ID | age | sex | location | time | Bacteria | abundance |
---|---|---|---|---|---|---|---|
1 | BUGA | 6 | F | A | September_2017 | Bacteria.A | 0.43 |
2 | BUGB | 6 | M | B | September_2017 | Bacteria.A | 0.50 |
3 | BUGC | 6 | F | A | September_2017 | Bacteria.A | 0.002 |
4 | BUGD | 6 | F | B | September_2017 | Bacteria.A | 0.034 |
5 | BUGE | 6 | F | A | September_2017 | Bacteria.A | 0.043 |
6 | BUGF | 6 | M | A | September_2017 | Bacteria.A | 0.023 |
7 | BUGA | 6 | F | A | March_2018 | Bacteria.A | 0.34 |
8 | BUGB | 6 | M | B | March_2018 | Bacteria.A | 0.23 |
9 | BUGA | 6 | F | A | September_2017 | Bacteria.A | 0.43 |
10 | BUGB | 6 | M | B | September_2017 | Bacteria.B | 0.50 |
11 | BUGC | 6 | F | A | September_2017 | Bacteria.B | 0.0000089 |
12 | BUGD | 6 | F | B | September_2017 | Bacteria.B | 0.034 |
13 | BUGE | 6 | F | A | September_2017 | Bacteria.B | 0.000079 |
14 | BUGF | 6 | M | A | September_2017 | Bacteria.B | 0.00098 |
15 | BUGA | 6 | F | A | March_2018 | Bacteria.B | 0.0034 |
16 | BUGB | 6 | M | B | March_2018 | Bacteria.B | 0.00012 |
data2 <- aggregate(data$abundance, list(data$location ,data$Bacteria),mean)
head(data2)
And this gives me an output that would look a bit like:
data2
Group.1 | Group.2 | value | |
---|---|---|---|
1 | A | Bacteria.A | mean value |
2 | B | Bacteria.A | mean value |
3 | A | Bacteria.B | mean value |
4 | B | Bacteria.B | mean value |
*where mean value would be a number = to the mean of all the values combined.
However, I would like this to be faceted by time-point also like this:
Group.1 | Group.2 | value | time | |
---|---|---|---|---|
1 | A | Bacteria.A | mean value | September_2017 |
2 | B | Bacteria.A | mean value | September_2017 |
3 | A | Bacteria.B | mean value | September_2017 |
4 | B | Bacteria.B | mean value | September_2017 |
5 | A | Bacteria.A | mean value | March_2018 |
6 | B | Bacteria.A | mean value | March_2018 |
7 | A | Bacteria.B | mean value | March_2018 |
8 | B | Bacteria.B | mean value | March_2018 |
Is this possible?
I've tried various pieces of code without success so any help would be much appreciated.
Thanks!
.