How to make a table summarizing sample size, mean, and standard deviation for each group


#1
obs     type     typen       food foodn typefood iron
1    1 Aluminum     1       meat     1       11 1.77
2    2 Aluminum     1       meat     1       11 2.36
3    3 Aluminum     1       meat     1       11 1.96
4    4 Aluminum     1       meat     1       11 2.14
5    5     Clay     2       meat     1       21 2.27
6    6     Clay     2       meat     1       21 1.28
7    7     Clay     2       meat     1       21 2.48
8    8     Clay     2       meat     1       21 2.68
9    9     Iron     3       meat     1       31 5.27
10  10     Iron     3       meat     1       31 5.17
11  11     Iron     3       meat     1       31 4.06
12  12     Iron     3       meat     1       31 4.22
13  13 Aluminum     1    legumes     2       12 2.40
14  14 Aluminum     1    legumes     2       12 2.17
15  15 Aluminum     1    legumes     2       12 2.41
16  16 Aluminum     1    legumes     2       12 2.34
17  17     Clay     2    legumes     2       22 2.41
18  18     Clay     2    legumes     2       22 2.43
19  19     Clay     2    legumes     2       22 2.57
20  20     Clay     2    legumes     2       22 2.48
21  21     Iron     3    legumes     2       32 3.69
22  22     Iron     3    legumes     2       32 3.43
23  23     Iron     3    legumes     2       32 3.84
24  24     Iron     3    legumes     2       32 3.72
25  25 Aluminum     1 vegetables     3       13 1.03
26  26 Aluminum     1 vegetables     3       13 1.53
27  27 Aluminum     1 vegetables     3       13 1.07
28  28 Aluminum     1 vegetables     3       13 1.30
29  29     Clay     2 vegetables     3       23 1.55
30  30     Clay     2 vegetables     3       23 0.79
31  31     Clay     2 vegetables     3       23 1.68
32  32     Clay     2 vegetables     3       23 1.82
33  33     Iron     3 vegetables     3       33 2.45
34  34     Iron     3 vegetables     3       33 2.99
35  35     Iron     3 vegetables     3       33 2.80
36  36     Iron     3 vegetables     3       33 2.92

This is data I'm using

I want to make a table giving the sample size, mean, and standard deviation by type(iron, clay, Aluminum )

How do I write the code for it?

*typen and foodn is number of type and food


#2

Hi,

I really recommend the R for Data Science book to teach you more about what is possible, specifically I think your problem is most quickly solved using tidyverse packages detailed in the "Data Transformation" chapter, see the section 5.6 Grouped summaries with summarise().

You also might find the rstudio.cloud primers useful, in particular the one called "Work with Data" has a section called Deriving Information with dplyr that also covers grouped summary statistics.

Alison