library(tidyverse)
library(skimr)


FastFood <- read_csv("https://github.com/rfordatascience/tidytuesday/raw/master/data/2018/2018-09-04/fastfood_calories.csv")
table(FastFood$restaurant)
## 
##       Arbys Burger King Chick Fil-A Dairy Queen   Mcdonalds       Sonic 
##          55          70          27          42          57          53 
##      Subway   Taco Bell 
##          96         115
skim(FastFood) # Summary of the data
## Skim summary statistics
##  n obs: 515 
##  n variables: 18 
##  group variables:  
## 
## ── Variable type:character ─────────────────────────────────────────────────────
##    variable missing complete   n min max empty n_unique
##        item       0      515 515   5  63     0      505
##  restaurant       0      515 515   5  11     0        8
##       salad       0      515 515   5   5     0        1
## 
## ── Variable type:integer ───────────────────────────────────────────────────────
##     variable missing complete   n    mean     sd p0   p25    p50    p75 p100
##      cal_fat       0      515 515  238.81 166.41  0 120    210    310   1270
##      calcium     210      305 515   24.85  25.52  0   8     20     30    290
##     calories       0      515 515  530.91 282.44 20 330    490    690   2430
##  cholesterol       0      515 515   72.46  63.16  0  35     60     95    805
##        fiber      12      503 515    4.14   3.04  0   2      3      5     17
##      protein       1      514 515   27.89  17.68  1  16     24.5   36    186
##       sodium       0      515 515 1246.74 689.95 15 800   1110   1550   6080
##        sugar       0      515 515    7.26   6.76  0   3      6      9     87
##   total_carb       0      515 515   45.66  24.88  0  28.5   44     57    156
##    total_fat       0      515 515   26.59  18.41  0  14     23     35    141
##        vit_a     214      301 515   18.86  31.38  0   4     10     20    180
##        vit_c     210      305 515   20.17  30.59  0   4     10     30    400
##           X1       0      515 515  258    148.81  1 129.5  258    386.5  515
##      hist
##  ▆▇▃▁▁▁▁▁
##  ▇▂▁▁▁▁▁▁
##  ▅▇▅▁▁▁▁▁
##  ▇▁▁▁▁▁▁▁
##  ▇▇▃▂▂▁▁▁
##  ▇▆▁▁▁▁▁▁
##  ▃▇▃▁▁▁▁▁
##  ▇▂▁▁▁▁▁▁
##  ▃▆▇▃▂▁▁▁
##  ▆▇▃▁▁▁▁▁
##  ▇▁▁▁▁▁▁▁
##  ▇▁▁▁▁▁▁▁
##  ▇▇▇▇▇▇▇▇
## 
## ── Variable type:numeric ───────────────────────────────────────────────────────
##   variable missing complete   n mean   sd p0 p25 p50 p75 p100     hist
##    sat_fat       0      515 515 8.15 6.42  0   4   7  11   47 ▇▇▂▁▁▁▁▁
##  trans_fat       0      515 515 0.47 0.84  0   0   0   1    8 ▇▁▁▁▁▁▁▁

Filter

FastFood %>% filter(restaurant == "Taco Bell")
## # A tibble: 115 x 18
##       X1 restaurant item  calories cal_fat total_fat sat_fat trans_fat
##    <int> <chr>      <chr>    <int>   <int>     <int>   <dbl>     <dbl>
##  1   401 Taco Bell  1/2 …      540     230        26       7         1
##  2   402 Taco Bell  1/2 …      460     170        18       7         1
##  3   403 Taco Bell  7-La…      510     170        19       7         0
##  4   404 Taco Bell  Bean…      370     100        11       4         0
##  5   405 Taco Bell  Beef…      550     200        22       8         0
##  6   406 Taco Bell  Beef…      440     160        18       5         0
##  7   407 Taco Bell  Blac…      410     110        12       4         0
##  8   408 Taco Bell  Burr…      420     140        16       7         0
##  9   409 Taco Bell  Burr…      390     110        12       5         0
## 10   410 Taco Bell  Burr…      390     120        13       5         0
## # … with 105 more rows, and 10 more variables: cholesterol <int>, sodium <int>,
## #   total_carb <int>, fiber <int>, sugar <int>, protein <int>, vit_a <int>,
## #   vit_c <int>, calcium <int>, salad <chr>
# Give me vectors where we want both Taco bell and Sonic
FastFood %>% filter(restaurant %in% c("Taco Bell", "Sonic")) 
## # A tibble: 168 x 18
##       X1 restaurant item  calories cal_fat total_fat sat_fat trans_fat
##    <int> <chr>      <chr>    <int>   <int>     <int>   <dbl>     <dbl>
##  1    85 Sonic      Hatc…      710     380        43      17       2  
##  2    86 Sonic      Jala…      640     330        37      14       2  
##  3    87 Sonic      Jr. …      340     150        17       6       1  
##  4    88 Sonic      Jr. …      410     220        24       9       0.5
##  5    89 Sonic      Jr. …      380     200        23       6       1  
##  6    90 Sonic      Jr. …      450     250        28       9       1  
##  7    91 Sonic      Jr. …      600     350        38      16       2  
##  8    92 Sonic      Soni…      870     530        59      20       2  
##  9    93 Sonic      Soni…      640     330        37      14       2  
## 10    94 Sonic      Soni…      650     340        37      14       2  
## # … with 158 more rows, and 10 more variables: cholesterol <int>, sodium <int>,
## #   total_carb <int>, fiber <int>, sugar <int>, protein <int>, vit_a <int>,
## #   vit_c <int>, calcium <int>, salad <chr>
# Find the item names that start with 'B'
FastFood %>% filter(startsWith(item, "B") == T)
## # A tibble: 48 x 18
##       X1 restaurant item  calories cal_fat total_fat sat_fat trans_fat
##    <int> <chr>      <chr>    <int>   <int>     <int>   <dbl>     <dbl>
##  1     6 Mcdonalds  Big …      540     250        28    10         1  
##  2   115 Sonic      Buff…     1000     550        61    12         0.5
##  3   140 Arbys      Beef…      450     180        20     6         1  
##  4   141 Arbys      Beef…      630     290        32    11         1.5
##  5   142 Arbys      Bour…      650     300        33    12         1  
##  6   143 Arbys      Bour…      690     280        31     9         0  
##  7   144 Arbys      Bour…      690     280        31     9         0  
##  8   145 Arbys      Butt…      540     220        24     4.5       0  
##  9   146 Arbys      Butt…      650     280        31     9         0  
## 10   147 Arbys      Butt…      690     310        35    10         0  
## # … with 38 more rows, and 10 more variables: cholesterol <int>, sodium <int>,
## #   total_carb <int>, fiber <int>, sugar <int>, protein <int>, vit_a <int>,
## #   vit_c <int>, calcium <int>, salad <chr>
# Resturant names starting with 'S'
FastFood %>% 
  filter(startsWith(restaurant,"S")==TRUE) %>%
  group_by(restaurant) %>% 
  skim() 
## Skim summary statistics
##  n obs: 149 
##  n variables: 18 
##  group variables: restaurant 
## 
## ── Variable type:character ─────────────────────────────────────────────────────
##  restaurant variable missing complete  n min max empty n_unique
##       Sonic     item       0       53 53   8  48     0       53
##       Sonic    salad       0       53 53   5   5     0        1
##      Subway     item       0       96 96   7  58     0       96
##      Subway    salad       0       96 96   5   5     0        1
## 
## ── Variable type:integer ───────────────────────────────────────────────────────
##  restaurant    variable missing complete  n    mean     sd  p0    p25    p50
##       Sonic     cal_fat       0       53 53  338.3  197.14 100 180     290  
##       Sonic     calcium       4       49 53   17.24  12.07   1   8      15  
##       Sonic    calories       0       53 53  631.7  300.88 100 410     570  
##       Sonic cholesterol       0       53 53   86.98  63.77   0  40      80  
##       Sonic       fiber       0       53 53    2.66   1.78   0   2       2  
##       Sonic     protein       0       53 53   29.19  14.53   6  18      30  
##       Sonic      sodium       0       53 53 1350.75 665.13 470 900    1250  
##       Sonic       sugar       0       53 53    6.53   3.94   0   4       7  
##       Sonic  total_carb       0       53 53   47.21  21.55  16  33      44  
##       Sonic   total_fat       0       53 53   37.64  21.97  11  20      32  
##       Sonic       vit_a       4       49 53    6.94   5.68   0   2       6  
##       Sonic       vit_c       4       49 53    5.76   4.81   0   2       6  
##       Sonic          X1       0       53 53  111     15.44  85  98     111  
##      Subway     cal_fat       0       96 96  165.1  134.84  10  48.75  137.5
##      Subway     calcium       0       96 96   39.12  25.13   4  20      35  
##      Subway    calories       0       96 96  503.02 282.22  50 287.5   460  
##      Subway cholesterol       0       96 96   61.3   40.93   0  40      50  
##      Subway       fiber       0       96 96    6.56   3.24   3   4       5  
##      Subway     protein       0       96 96   30.31  16.14   3  18      26  
##      Subway      sodium       0       96 96 1272.97 743.63  65 697.5  1130  
##      Subway       sugar       0       96 96   10.09   5.61   3   6       8  
##      Subway  total_carb       0       96 96   54.72  33.31   8  25.75   47  
##      Subway   total_fat       0       96 96   18.48  14.61   1   6      15  
##      Subway       vit_a       0       96 96   22.39  15.14   6  10      16  
##      Subway       vit_c       0       96 96   41.97  44.01   4  20      40  
##      Subway          X1       0       96 96  352.5   27.86 305 328.75  352.5
##      p75 p100     hist
##   430     900 ▇▅▅▂▂▂▁▁
##    27      40 ▇▇▆▆▂▆▁▃
##   740    1350 ▁▇▇▇▃▁▃▂
##   110     260 ▂▇▅▅▁▁▁▂
##     3       8 ▅▇▂▂▂▁▁▁
##    35      67 ▂▆▃▇▃▁▁▂
##  1550    4520 ▇▇▅▂▁▁▁▁
##     9      17 ▅▃▂▇▃▃▁▁
##    51     126 ▃▇▇▃▁▁▁▁
##    48     100 ▇▆▅▂▂▂▁▁
##    10      20 ▇▂▅▃▁▃▁▁
##     8      25 ▇▅▇▂▁▁▁▁
##   124     137 ▇▇▇▇▇▇▇▇
##   242.5   620 ▇▅▃▂▁▁▁▁
##    60     100 ▆▂▇▂▅▂▂▁
##   740    1160 ▅▇▆▆▅▅▃▂
##    85     190 ▅▇▇▅▃▁▁▁
##    10      16 ▇▇▁▁▆▁▁▁
##    40      78 ▃▇▆▆▃▂▁▁
##  1605    3540 ▃▇▇▆▁▂▂▁
##    14      36 ▇▅▂▃▁▁▁▁
##    92     118 ▇▂▇▂▁▂▇▁
##    26.5    62 ▇▆▂▃▃▁▁▁
##    30      60 ▇▆▅▂▁▁▃▁
##    50     400 ▇▁▁▁▁▁▁▁
##   376.25  400 ▇▇▇▇▇▇▇▇
## 
## ── Variable type:numeric ───────────────────────────────────────────────────────
##  restaurant  variable missing complete  n  mean   sd  p0 p25 p50   p75 p100
##       Sonic   sat_fat       0       53 53 11.42 8.67 2.5   5 8   15      36
##       Sonic trans_fat       0       53 53  0.93 1.26 0     0 0    2       4
##      Subway   sat_fat       0       96 96  6.2  5.24 0     2 4.5  9.25   22
##      Subway trans_fat       0       96 96  0.22 0.52 0     0 0    0       2
##      hist
##  ▇▇▃▂▁▁▁▂
##  ▇▂▁▂▁▁▁▁
##  ▇▅▃▃▂▁▁▁
##  ▇▁▁▁▁▁▁▁
FastFood %>%
  filter(startsWith(item, "M") == TRUE | startsWith(item, "A") == TRUE)
## # A tibble: 19 x 18
##       X1 restaurant item  calories cal_fat total_fat sat_fat trans_fat
##    <int> <chr>      <chr>    <int>   <int>     <int>   <dbl>     <dbl>
##  1     1 Mcdonalds  "Art…      380      60         7     2         0  
##  2    17 Mcdonalds  "Map…      640     330        36    14         1.5
##  3    20 Mcdonalds  "McC…      350     130        15     3.5       0  
##  4    21 Mcdonalds  "McD…      380     160        18     8         1  
##  5    22 Mcdonalds  "McR…      480     200        22     7         0  
##  6   129 Sonic      "All…      370     160        18     7         0  
##  7   130 Sonic      "All…      430     180        20     7         0  
##  8   131 Sonic      "All…      410     230        26    11         0  
##  9   132 Sonic      "All…      340     170        19     7         0  
## 10   133 Sonic      "All…      320     160        18     7         0  
## 11   138 Arbys      "Arb…      330     100        11     4         0  
## 12   139 Arbys      "Arb…      400      90        10     3         0  
## 13   193 Burger Ki… "Ame…     1550    1134       126    47         8  
## 14   210 Burger Ki… "Mus…      940     567        63    21         2.5
## 15   369 Subway     "Aut…      300      80         9     3         0  
## 16   382 Subway     "Mea…      310     150        17     7         1  
## 17   460 Taco Bell  "Mil…      440     270        30     7         0  
## 18   500 Taco Bell  "Mex…      540     270        31     8         1  
## 19   501 Taco Bell  "Mex…      270     130        14     7         1  
## # … with 10 more variables: cholesterol <int>, sodium <int>, total_carb <int>,
## #   fiber <int>, sugar <int>, protein <int>, vit_a <int>, vit_c <int>,
## #   calcium <int>, salad <chr>
FastFood %>%
  filter(startsWith(item, "B") == TRUE | endsWith(item, "C") == TRUE)
## # A tibble: 48 x 18
##       X1 restaurant item  calories cal_fat total_fat sat_fat trans_fat
##    <int> <chr>      <chr>    <int>   <int>     <int>   <dbl>     <dbl>
##  1     6 Mcdonalds  Big …      540     250        28    10         1  
##  2   115 Sonic      Buff…     1000     550        61    12         0.5
##  3   140 Arbys      Beef…      450     180        20     6         1  
##  4   141 Arbys      Beef…      630     290        32    11         1.5
##  5   142 Arbys      Bour…      650     300        33    12         1  
##  6   143 Arbys      Bour…      690     280        31     9         0  
##  7   144 Arbys      Bour…      690     280        31     9         0  
##  8   145 Arbys      Butt…      540     220        24     4.5       0  
##  9   146 Arbys      Butt…      650     280        31     9         0  
## 10   147 Arbys      Butt…      690     310        35    10         0  
## # … with 38 more rows, and 10 more variables: cholesterol <int>, sodium <int>,
## #   total_carb <int>, fiber <int>, sugar <int>, protein <int>, vit_a <int>,
## #   vit_c <int>, calcium <int>, salad <chr>
# pause, Not!
FastFood %>%
  filter(!(startsWith(restaurant, "S")== TRUE)) %>% group_by(restaurant) %>% skim()
## Skim summary statistics
##  n obs: 366 
##  n variables: 18 
##  group variables: restaurant 
## 
## ── Variable type:character ─────────────────────────────────────────────────────
##   restaurant variable missing complete   n min max empty n_unique
##        Arbys     item       0       55  55  10  39     0       55
##        Arbys    salad       0       55  55   5   5     0        1
##  Burger King     item       0       70  70   9  63     0       70
##  Burger King    salad       0       70  70   5   5     0        1
##  Chick Fil-A     item       0       27  27  12  36     0       27
##  Chick Fil-A    salad       0       27  27   5   5     0        1
##  Dairy Queen     item       0       42  42   7  45     0       42
##  Dairy Queen    salad       0       42  42   5   5     0        1
##    Mcdonalds     item       0       57  57   5  49     0       57
##    Mcdonalds    salad       0       57  57   5   5     0        1
##    Taco Bell     item       0      115 115   7  45     0      113
##    Taco Bell    salad       0      115 115   5   5     0        1
## 
## ── Variable type:integer ───────────────────────────────────────────────────────
##   restaurant    variable missing complete   n    mean      sd  p0    p25    p50
##        Arbys     cal_fat       0       55  55  237.84  113.17  45 135     250  
##        Arbys     calcium      30       25  55   17.36   12.71   2   8      15  
##        Arbys    calories       0       55  55  532.73  210.34  70 360     550  
##        Arbys cholesterol       0       55  55   70.45   34.31  15  45      65  
##        Arbys       fiber       0       55  55    2.71    1.41   1   2       2  
##        Arbys     protein       0       55  55   29.25   12.39   5  20      29  
##        Arbys      sodium       0       55  55 1515.27  663.67 100 960    1480  
##        Arbys       sugar       0       55  55    7.56    5.86   0   3.5     6  
##        Arbys  total_carb       0       55  55   44.87   19.1    4  34      46  
##        Arbys   total_fat       0       55  55   26.98   13.24   5  15.5    28  
##        Arbys       vit_a      30       25  55   12.56   16.83   0   2       6  
##        Arbys       vit_c      30       25  55    8.4     6.34   0   2      10  
##        Arbys          X1       0       55  55  165      16.02 138 151.5   165  
##  Burger King     cal_fat       0       70  70  333.76  194.5   90 172.5   285  
##  Burger King     calcium      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King    calories       0       70  70  608.57  290.42 190 365     555  
##  Burger King cholesterol       0       70  70  100.86  107.32   5  40      85  
##  Burger King       fiber      10       60  70    2.38    1.35   0   1.75    2  
##  Burger King     protein       1       69  70   30.01   19.47   5  16      29  
##  Burger King      sodium       0       70  70 1223.57  499.88 310 850    1150  
##  Burger King       sugar       0       70  70    8.19    6.19   0   6       7.5
##  Burger King  total_carb       0       70  70   39.31   15.56   7  28      41  
##  Burger King   total_fat       0       70  70   36.81   21.24  10  19.25   31.5
##  Burger King       vit_a      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King       vit_c      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King          X1       0       70  70  227.5    20.35 193 210.25  227.5
##  Chick Fil-A     cal_fat       0       27  27  145.37  102.36  18  67.5   126  
##  Chick Fil-A     calcium       2       25  27   11.32   10.49   0   2       8  
##  Chick Fil-A    calories       0       27  27  384.44  220.49  70 220     390  
##  Chick Fil-A cholesterol       0       27  27   79.07   47.31  25  55      70  
##  Chick Fil-A       fiber       2       25  27    2.32    3.05   0   1       1  
##  Chick Fil-A     protein       0       27  27   31.7    16.93  11  23.5    29  
##  Chick Fil-A      sodium       0       27  27 1151.48  726.92 220 700    1000  
##  Chick Fil-A       sugar       0       27  27    4.15    3.67   0   1       4  
##  Chick Fil-A  total_carb       0       27  27   28.63   20.43   1   8      29  
##  Chick Fil-A   total_fat       0       27  27   16.15   11.38   2   7.5    14  
##  Chick Fil-A       vit_a       6       21  27   12.62   18.52   0   0       2  
##  Chick Fil-A       vit_c       2       25  27   14.08   15.26   0   2       8  
##  Chick Fil-A          X1       0       27  27   71       7.94  58  64.5    71  
##  Dairy Queen     cal_fat       0       42  42  260.48  156.49   0 160     220  
##  Dairy Queen     calcium      15       27  42   16.41   19.02   0   6      10  
##  Dairy Queen    calories       0       42  42  520.24  259.34  20 350     485  
##  Dairy Queen cholesterol       0       42  42   71.55   43.75   0  41.25   60  
##  Dairy Queen       fiber       0       42  42    2.83    2.92   0   1       2  
##  Dairy Queen     protein       0       42  42   24.83   11.54   1  17      23  
##  Dairy Queen      sodium       0       42  42 1181.79  609.94  15 847.5  1030  
##  Dairy Queen       sugar       0       42  42    6.36    5.03   0   3       6  
##  Dairy Queen  total_carb       0       42  42   38.69   23.73   0  25.25   34  
##  Dairy Queen   total_fat       0       42  42   28.86   17.52   0  18      24.5
##  Dairy Queen       vit_a      15       27  42   14      11.01   0   9      10  
##  Dairy Queen       vit_c      15       27  42    4.37    5.87   0   0       4  
##  Dairy Queen          X1       0       42  42  283.5    12.27 263 273.25  283.5
##    Mcdonalds     cal_fat       0       57  57  285.61  220.9   50 160     240  
##    Mcdonalds     calcium       0       57  57   20.6    37.93   0   6      15  
##    Mcdonalds    calories       0       57  57  640.35  410.7  140 380     540  
##    Mcdonalds cholesterol       0       57  57  109.74   79.53   0  70      95  
##    Mcdonalds       fiber       0       57  57    3.23    1.66   0   2       3  
##    Mcdonalds     protein       0       57  57   40.3    29.48   7  25      33  
##    Mcdonalds      sodium       0       57  57 1437.89 1036.17  20 870    1120  
##    Mcdonalds       sugar       0       57  57   11.07   13.35   0   4       9  
##    Mcdonalds  total_carb       0       57  57   48.79   26.44   9  32      46  
##    Mcdonalds   total_fat       0       57  57   31.81   24.52   5  18      27  
##    Mcdonalds       vit_a       0       57  57   33.72   64.16   0   2       6  
##    Mcdonalds       vit_c       0       57  57   18.3    18.08   0   2      15  
##    Mcdonalds          X1       0       57  57   29      16.6    1  15      29  
##    Taco Bell     cal_fat       0      115 115  188      84.81  35 120     180  
##    Taco Bell     calcium      89       26 115   24.81   11.33   6  15      25  
##    Taco Bell    calories       0      115 115  443.65  184.34 140 320     420  
##    Taco Bell cholesterol       0      115 115   39.04   19.19   0  25      35  
##    Taco Bell       fiber       0      115 115    5.71    3.06   1   3       5  
##    Taco Bell     protein       0      115 115   17.42    7.14   6  12      16  
##    Taco Bell      sodium       0      115 115 1013.91  474.05 290 615     960  
##    Taco Bell       sugar       0      115 115    3.7     1.89   1   2       4  
##    Taco Bell  total_carb       0      115 115   46.63   22.52  12  29      44  
##    Taco Bell   total_fat       0      115 115   20.9     9.41   4  13      20  
##    Taco Bell       vit_a      89       26 115   11.85    3.94   6   8.5    12.5
##    Taco Bell       vit_c      89       26 115    4.54    2.44   0   2       4  
##    Taco Bell          X1       0      115 115  458      33.34 401 429.5   458  
##      p75 p100     hist
##   310     495 ▆▃▃▇▇▂▂▂
##    25      45 ▇▇▇▁▃▁▂▂
##   690    1030 ▁▇▅▆▆▇▁▁
##    90     155 ▇▅▇▇▅▃▂▂
##     4       6 ▃▇▁▃▃▁▂▁
##    38      62 ▂▇▇▆▇▅▂▂
##  2020    3350 ▁▆▇▅▇▃▁▁
##     9      23 ▇▇▆▅▁▅▂▁
##    54      83 ▂▃▂▅▇▃▁▃
##    35      59 ▆▅▅▇▆▂▁▂
##    20      60 ▇▃▂▁▁▁▁▁
##    10      20 ▅▁▁▇▁▁▁▂
##   178.5   192 ▇▇▇▇▇▇▇▇
##   431.5  1134 ▇▆▅▂▂▁▁▁
##    NA      NA         
##   760    1550 ▇▇▆▃▃▁▁▁
##   115     805 ▇▂▁▁▁▁▁▁
##     3       7 ▁▅▇▃▁▂▁▁
##    36     134 ▆▇▂▂▁▁▁▁
##  1635    2310 ▅▅▇▅▇▆▃▂
##    10      37 ▃▇▃▁▁▁▁▁
##    52      69 ▂▃▆▅▃▇▅▂
##    48     126 ▇▆▅▃▂▁▁▁
##    NA      NA         
##    NA      NA         
##   244.75  262 ▇▇▇▇▇▇▇▇
##   171     423 ▇▇▆▆▁▁▁▂
##    20      35 ▇▂▂▂▂▂▁▁
##   480     970 ▅▅▃▇▁▁▁▂
##    87.5   285 ▅▇▃▁▁▁▁▁
##     3      15 ▇▅▂▁▁▁▁▁
##    37     103 ▅▇▃▁▁▁▁▁
##  1405    3660 ▆▇▇▃▁▁▁▁
##     7      12 ▇▂▂▃▂▂▂▁
##    42.5    70 ▇▂▂▃▆▃▁▂
##    19      47 ▇▇▆▆▁▁▁▂
##    30      60 ▇▁▁▂▁▁▁▁
##    20      50 ▇▅▁▂▁▁▂▁
##    77.5    84 ▇▆▆▇▆▆▆▇
##   310     670 ▂▅▇▅▁▃▁▂
##    20     100 ▇▅▁▁▁▁▁▁
##   630    1260 ▁▅▇▇▁▁▂▁
##   100     180 ▂▆▇▂▃▂▁▁
##     3      12 ▇▇▁▁▁▁▁▁
##    34      49 ▂▃▇▆▂▆▃▂
##  1362.5  3500 ▁▃▇▃▁▁▁▁
##     8.75   30 ▇▇▅▂▁▁▁▁
##    44.75  121 ▂▆▇▂▁▁▁▁
##    34.75   75 ▂▅▇▅▁▃▁▂
##    20      50 ▅▇▂▆▁▁▁▁
##     6      30 ▇▇▁▁▁▁▁▁
##   293.75  304 ▇▇▇▇▇▇▇▇
##   320    1270 ▇▆▂▁▁▁▁▁
##    20     290 ▇▁▁▁▁▁▁▁
##   740    2430 ▅▇▃▁▁▁▁▁
##   125     475 ▃▇▂▁▁▁▁▁
##     4       8 ▃▇▇▅▃▂▁▁
##    46     186 ▆▇▁▁▁▁▁▁
##  1780    6080 ▃▇▃▁▁▁▁▁
##    13      87 ▇▅▁▁▁▁▁▁
##    62     156 ▅▆▇▂▁▁▁▁
##    36     141 ▇▇▂▁▁▁▁▁
##    20     180 ▇▁▁▁▁▁▁▂
##    25      70 ▇▃▅▁▁▁▁▁
##    43      57 ▇▇▇▇▇▇▇▇
##   250     380 ▂▇▃▅▆▃▂▂
##    35      45 ▃▃▃▂▂▇▁▁
##   575     880 ▇▅▇▇▇▃▅▁
##    55      85 ▂▂▇▅▃▃▂▂
##     7      17 ▇▇▆▃▂▁▁▁
##    22      37 ▆▇▇▆▆▂▂▁
##  1300    2260 ▇▇▇▇▅▂▂▂
##     5       8 ▅▆▇▇▆▂▃▂
##    64     107 ▇▃▇▆▅▂▂▁
##    28      42 ▂▇▇▆▂▆▃▂
##    15      20 ▂▂▃▁▁▇▁▁
##     6      10 ▁▇▁▇▇▁▃▁
##   486.5   515 ▇▇▇▇▇▇▇▇
## 
## ── Variable type:numeric ───────────────────────────────────────────────────────
##   restaurant  variable missing complete   n   mean   sd  p0 p25 p50   p75 p100
##        Arbys   sat_fat       0       55  55  7.97  4.16 1.5 4.5   7 11      17
##        Arbys trans_fat       0       55  55  0.42  0.59 0   0     0  1       2
##  Burger King   sat_fat       0       70  70 11.15  8.77 2   5     8 13.75   47
##  Burger King trans_fat       0       70  70  0.86  1.35 0   0     0  1.38    8
##  Chick Fil-A   sat_fat       0       27  27  4.11  3.9  0   1.5   3  4.75   16
##  Chick Fil-A trans_fat       0       27  27  0.037 0.19 0   0     0  0       1
##  Dairy Queen   sat_fat       0       42  42 10.44  8.25 0   5     9 12.5    43
##  Dairy Queen trans_fat       0       42  42  0.68  0.71 0   0     1  1       2
##    Mcdonalds   sat_fat       0       57  57  8.29  5.53 0.5 4.5   7 11      27
##    Mcdonalds trans_fat       0       57  57  0.46  0.72 0   0     0  1       3
##    Taco Bell   sat_fat       0      115 115  6.59  2.98 1   4     6  9      14
##    Taco Bell trans_fat       0      115 115  0.26  0.4  0   0     0  0.5     1
##      hist
##  ▅▇▆▅▅▃▃▁
##  ▇▂▁▂▁▁▁▁
##  ▇▅▁▂▁▁▁▁
##  ▇▁▁▁▁▁▁▁
##  ▇▇▂▂▁▁▁▂
##  ▇▁▁▁▁▁▁▁
##  ▇▇▆▂▂▁▁▁
##  ▇▁▁▇▁▁▁▂
##  ▃▇▅▃▂▁▁▁
##  ▇▂▁▂▁▁▁▁
##  ▂▇▆▆▆▃▃▁
##  ▇▁▁▂▁▁▁▂

Select

FastFood %>% select(restaurant, calories)
## # A tibble: 515 x 2
##    restaurant calories
##    <chr>         <int>
##  1 Mcdonalds       380
##  2 Mcdonalds       840
##  3 Mcdonalds      1130
##  4 Mcdonalds       750
##  5 Mcdonalds       920
##  6 Mcdonalds       540
##  7 Mcdonalds       300
##  8 Mcdonalds       510
##  9 Mcdonalds       430
## 10 Mcdonalds       770
## # … with 505 more rows
FastFood %>% select(restaurant, starts_with("vit")) # different starts_with than filter
## # A tibble: 515 x 3
##    restaurant vit_a vit_c
##    <chr>      <int> <int>
##  1 Mcdonalds      4    20
##  2 Mcdonalds      6    20
##  3 Mcdonalds     10    20
##  4 Mcdonalds      6    25
##  5 Mcdonalds      6    20
##  6 Mcdonalds     10     2
##  7 Mcdonalds     10     2
##  8 Mcdonalds      0     4
##  9 Mcdonalds     20     4
## 10 Mcdonalds     20     6
## # … with 505 more rows
FastFood %>% select(-restaurant)
## # A tibble: 515 x 17
##       X1 item  calories cal_fat total_fat sat_fat trans_fat cholesterol sodium
##    <int> <chr>    <int>   <int>     <int>   <dbl>     <dbl>       <int>  <int>
##  1     1 Arti…      380      60         7       2       0            95   1110
##  2     2 Sing…      840     410        45      17       1.5         130   1580
##  3     3 Doub…     1130     600        67      27       3           220   1920
##  4     4 Gril…      750     280        31      10       0.5         155   1940
##  5     5 Cris…      920     410        45      12       0.5         120   1980
##  6     6 Big …      540     250        28      10       1            80    950
##  7     7 Chee…      300     100        12       5       0.5          40    680
##  8     8 Clas…      510     210        24       4       0            65   1040
##  9     9 Doub…      430     190        21      11       1            85   1040
## 10    10 Doub…      770     400        45      21       2.5         175   1290
## # … with 505 more rows, and 8 more variables: total_carb <int>, fiber <int>,
## #   sugar <int>, protein <int>, vit_a <int>, vit_c <int>, calcium <int>,
## #   salad <chr>

Mutate() & Transmute()

Transmute is about to disapear

FastFood<- FastFood %>%
  mutate(Sodium.Grams = sodium / 1000) %>%
  select(restaurant, Sodium.Grams, sodium, everything())

#FastFood <- FastFood %>%
 # transmute(Sodium.Grams = sodium / 1000)

FastFood <- FastFood %>% mutate(Chicken = stringr::str_detect(item, 'Chicken|Chick-n'))

head(FastFood)
## # A tibble: 6 x 20
##   restaurant Sodium.Grams sodium    X1 item  calories cal_fat total_fat sat_fat
##   <chr>             <dbl>  <int> <int> <chr>    <int>   <int>     <int>   <dbl>
## 1 Mcdonalds          1.11   1110     1 Arti…      380      60         7       2
## 2 Mcdonalds          1.58   1580     2 Sing…      840     410        45      17
## 3 Mcdonalds          1.92   1920     3 Doub…     1130     600        67      27
## 4 Mcdonalds          1.94   1940     4 Gril…      750     280        31      10
## 5 Mcdonalds          1.98   1980     5 Cris…      920     410        45      12
## 6 Mcdonalds          0.95    950     6 Big …      540     250        28      10
## # … with 11 more variables: trans_fat <dbl>, cholesterol <int>,
## #   total_carb <int>, fiber <int>, sugar <int>, protein <int>, vit_a <int>,
## #   vit_c <int>, calcium <int>, salad <chr>, Chicken <lgl>

Group_by()

FastFood %>% 
  group_by(restaurant) %>% skim()
## Skim summary statistics
##  n obs: 515 
##  n variables: 20 
##  group variables: restaurant 
## 
## ── Variable type:character ─────────────────────────────────────────────────────
##   restaurant variable missing complete   n min max empty n_unique
##        Arbys     item       0       55  55  10  39     0       55
##        Arbys    salad       0       55  55   5   5     0        1
##  Burger King     item       0       70  70   9  63     0       70
##  Burger King    salad       0       70  70   5   5     0        1
##  Chick Fil-A     item       0       27  27  12  36     0       27
##  Chick Fil-A    salad       0       27  27   5   5     0        1
##  Dairy Queen     item       0       42  42   7  45     0       42
##  Dairy Queen    salad       0       42  42   5   5     0        1
##    Mcdonalds     item       0       57  57   5  49     0       57
##    Mcdonalds    salad       0       57  57   5   5     0        1
##        Sonic     item       0       53  53   8  48     0       53
##        Sonic    salad       0       53  53   5   5     0        1
##       Subway     item       0       96  96   7  58     0       96
##       Subway    salad       0       96  96   5   5     0        1
##    Taco Bell     item       0      115 115   7  45     0      113
##    Taco Bell    salad       0      115 115   5   5     0        1
## 
## ── Variable type:integer ───────────────────────────────────────────────────────
##   restaurant    variable missing complete   n    mean      sd  p0    p25    p50
##        Arbys     cal_fat       0       55  55  237.84  113.17  45 135     250  
##        Arbys     calcium      30       25  55   17.36   12.71   2   8      15  
##        Arbys    calories       0       55  55  532.73  210.34  70 360     550  
##        Arbys cholesterol       0       55  55   70.45   34.31  15  45      65  
##        Arbys       fiber       0       55  55    2.71    1.41   1   2       2  
##        Arbys     protein       0       55  55   29.25   12.39   5  20      29  
##        Arbys      sodium       0       55  55 1515.27  663.67 100 960    1480  
##        Arbys       sugar       0       55  55    7.56    5.86   0   3.5     6  
##        Arbys  total_carb       0       55  55   44.87   19.1    4  34      46  
##        Arbys   total_fat       0       55  55   26.98   13.24   5  15.5    28  
##        Arbys       vit_a      30       25  55   12.56   16.83   0   2       6  
##        Arbys       vit_c      30       25  55    8.4     6.34   0   2      10  
##        Arbys          X1       0       55  55  165      16.02 138 151.5   165  
##  Burger King     cal_fat       0       70  70  333.76  194.5   90 172.5   285  
##  Burger King     calcium      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King    calories       0       70  70  608.57  290.42 190 365     555  
##  Burger King cholesterol       0       70  70  100.86  107.32   5  40      85  
##  Burger King       fiber      10       60  70    2.38    1.35   0   1.75    2  
##  Burger King     protein       1       69  70   30.01   19.47   5  16      29  
##  Burger King      sodium       0       70  70 1223.57  499.88 310 850    1150  
##  Burger King       sugar       0       70  70    8.19    6.19   0   6       7.5
##  Burger King  total_carb       0       70  70   39.31   15.56   7  28      41  
##  Burger King   total_fat       0       70  70   36.81   21.24  10  19.25   31.5
##  Burger King       vit_a      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King       vit_c      70        0  70  NaN      NA     NA  NA      NA  
##  Burger King          X1       0       70  70  227.5    20.35 193 210.25  227.5
##  Chick Fil-A     cal_fat       0       27  27  145.37  102.36  18  67.5   126  
##  Chick Fil-A     calcium       2       25  27   11.32   10.49   0   2       8  
##  Chick Fil-A    calories       0       27  27  384.44  220.49  70 220     390  
##  Chick Fil-A cholesterol       0       27  27   79.07   47.31  25  55      70  
##  Chick Fil-A       fiber       2       25  27    2.32    3.05   0   1       1  
##  Chick Fil-A     protein       0       27  27   31.7    16.93  11  23.5    29  
##  Chick Fil-A      sodium       0       27  27 1151.48  726.92 220 700    1000  
##  Chick Fil-A       sugar       0       27  27    4.15    3.67   0   1       4  
##  Chick Fil-A  total_carb       0       27  27   28.63   20.43   1   8      29  
##  Chick Fil-A   total_fat       0       27  27   16.15   11.38   2   7.5    14  
##  Chick Fil-A       vit_a       6       21  27   12.62   18.52   0   0       2  
##  Chick Fil-A       vit_c       2       25  27   14.08   15.26   0   2       8  
##  Chick Fil-A          X1       0       27  27   71       7.94  58  64.5    71  
##  Dairy Queen     cal_fat       0       42  42  260.48  156.49   0 160     220  
##  Dairy Queen     calcium      15       27  42   16.41   19.02   0   6      10  
##  Dairy Queen    calories       0       42  42  520.24  259.34  20 350     485  
##  Dairy Queen cholesterol       0       42  42   71.55   43.75   0  41.25   60  
##  Dairy Queen       fiber       0       42  42    2.83    2.92   0   1       2  
##  Dairy Queen     protein       0       42  42   24.83   11.54   1  17      23  
##  Dairy Queen      sodium       0       42  42 1181.79  609.94  15 847.5  1030  
##  Dairy Queen       sugar       0       42  42    6.36    5.03   0   3       6  
##  Dairy Queen  total_carb       0       42  42   38.69   23.73   0  25.25   34  
##  Dairy Queen   total_fat       0       42  42   28.86   17.52   0  18      24.5
##  Dairy Queen       vit_a      15       27  42   14      11.01   0   9      10  
##  Dairy Queen       vit_c      15       27  42    4.37    5.87   0   0       4  
##  Dairy Queen          X1       0       42  42  283.5    12.27 263 273.25  283.5
##    Mcdonalds     cal_fat       0       57  57  285.61  220.9   50 160     240  
##    Mcdonalds     calcium       0       57  57   20.6    37.93   0   6      15  
##    Mcdonalds    calories       0       57  57  640.35  410.7  140 380     540  
##    Mcdonalds cholesterol       0       57  57  109.74   79.53   0  70      95  
##    Mcdonalds       fiber       0       57  57    3.23    1.66   0   2       3  
##    Mcdonalds     protein       0       57  57   40.3    29.48   7  25      33  
##    Mcdonalds      sodium       0       57  57 1437.89 1036.17  20 870    1120  
##    Mcdonalds       sugar       0       57  57   11.07   13.35   0   4       9  
##    Mcdonalds  total_carb       0       57  57   48.79   26.44   9  32      46  
##    Mcdonalds   total_fat       0       57  57   31.81   24.52   5  18      27  
##    Mcdonalds       vit_a       0       57  57   33.72   64.16   0   2       6  
##    Mcdonalds       vit_c       0       57  57   18.3    18.08   0   2      15  
##    Mcdonalds          X1       0       57  57   29      16.6    1  15      29  
##        Sonic     cal_fat       0       53  53  338.3   197.14 100 180     290  
##        Sonic     calcium       4       49  53   17.24   12.07   1   8      15  
##        Sonic    calories       0       53  53  631.7   300.88 100 410     570  
##        Sonic cholesterol       0       53  53   86.98   63.77   0  40      80  
##        Sonic       fiber       0       53  53    2.66    1.78   0   2       2  
##        Sonic     protein       0       53  53   29.19   14.53   6  18      30  
##        Sonic      sodium       0       53  53 1350.75  665.13 470 900    1250  
##        Sonic       sugar       0       53  53    6.53    3.94   0   4       7  
##        Sonic  total_carb       0       53  53   47.21   21.55  16  33      44  
##        Sonic   total_fat       0       53  53   37.64   21.97  11  20      32  
##        Sonic       vit_a       4       49  53    6.94    5.68   0   2       6  
##        Sonic       vit_c       4       49  53    5.76    4.81   0   2       6  
##        Sonic          X1       0       53  53  111      15.44  85  98     111  
##       Subway     cal_fat       0       96  96  165.1   134.84  10  48.75  137.5
##       Subway     calcium       0       96  96   39.12   25.13   4  20      35  
##       Subway    calories       0       96  96  503.02  282.22  50 287.5   460  
##       Subway cholesterol       0       96  96   61.3    40.93   0  40      50  
##       Subway       fiber       0       96  96    6.56    3.24   3   4       5  
##       Subway     protein       0       96  96   30.31   16.14   3  18      26  
##       Subway      sodium       0       96  96 1272.97  743.63  65 697.5  1130  
##       Subway       sugar       0       96  96   10.09    5.61   3   6       8  
##       Subway  total_carb       0       96  96   54.72   33.31   8  25.75   47  
##       Subway   total_fat       0       96  96   18.48   14.61   1   6      15  
##       Subway       vit_a       0       96  96   22.39   15.14   6  10      16  
##       Subway       vit_c       0       96  96   41.97   44.01   4  20      40  
##       Subway          X1       0       96  96  352.5    27.86 305 328.75  352.5
##    Taco Bell     cal_fat       0      115 115  188      84.81  35 120     180  
##    Taco Bell     calcium      89       26 115   24.81   11.33   6  15      25  
##    Taco Bell    calories       0      115 115  443.65  184.34 140 320     420  
##    Taco Bell cholesterol       0      115 115   39.04   19.19   0  25      35  
##    Taco Bell       fiber       0      115 115    5.71    3.06   1   3       5  
##    Taco Bell     protein       0      115 115   17.42    7.14   6  12      16  
##    Taco Bell      sodium       0      115 115 1013.91  474.05 290 615     960  
##    Taco Bell       sugar       0      115 115    3.7     1.89   1   2       4  
##    Taco Bell  total_carb       0      115 115   46.63   22.52  12  29      44  
##    Taco Bell   total_fat       0      115 115   20.9     9.41   4  13      20  
##    Taco Bell       vit_a      89       26 115   11.85    3.94   6   8.5    12.5
##    Taco Bell       vit_c      89       26 115    4.54    2.44   0   2       4  
##    Taco Bell          X1       0      115 115  458      33.34 401 429.5   458  
##      p75 p100     hist
##   310     495 ▆▃▃▇▇▂▂▂
##    25      45 ▇▇▇▁▃▁▂▂
##   690    1030 ▁▇▅▆▆▇▁▁
##    90     155 ▇▅▇▇▅▃▂▂
##     4       6 ▃▇▁▃▃▁▂▁
##    38      62 ▂▇▇▆▇▅▂▂
##  2020    3350 ▁▆▇▅▇▃▁▁
##     9      23 ▇▇▆▅▁▅▂▁
##    54      83 ▂▃▂▅▇▃▁▃
##    35      59 ▆▅▅▇▆▂▁▂
##    20      60 ▇▃▂▁▁▁▁▁
##    10      20 ▅▁▁▇▁▁▁▂
##   178.5   192 ▇▇▇▇▇▇▇▇
##   431.5  1134 ▇▆▅▂▂▁▁▁
##    NA      NA         
##   760    1550 ▇▇▆▃▃▁▁▁
##   115     805 ▇▂▁▁▁▁▁▁
##     3       7 ▁▅▇▃▁▂▁▁
##    36     134 ▆▇▂▂▁▁▁▁
##  1635    2310 ▅▅▇▅▇▆▃▂
##    10      37 ▃▇▃▁▁▁▁▁
##    52      69 ▂▃▆▅▃▇▅▂
##    48     126 ▇▆▅▃▂▁▁▁
##    NA      NA         
##    NA      NA         
##   244.75  262 ▇▇▇▇▇▇▇▇
##   171     423 ▇▇▆▆▁▁▁▂
##    20      35 ▇▂▂▂▂▂▁▁
##   480     970 ▅▅▃▇▁▁▁▂
##    87.5   285 ▅▇▃▁▁▁▁▁
##     3      15 ▇▅▂▁▁▁▁▁
##    37     103 ▅▇▃▁▁▁▁▁
##  1405    3660 ▆▇▇▃▁▁▁▁
##     7      12 ▇▂▂▃▂▂▂▁
##    42.5    70 ▇▂▂▃▆▃▁▂
##    19      47 ▇▇▆▆▁▁▁▂
##    30      60 ▇▁▁▂▁▁▁▁
##    20      50 ▇▅▁▂▁▁▂▁
##    77.5    84 ▇▆▆▇▆▆▆▇
##   310     670 ▂▅▇▅▁▃▁▂
##    20     100 ▇▅▁▁▁▁▁▁
##   630    1260 ▁▅▇▇▁▁▂▁
##   100     180 ▂▆▇▂▃▂▁▁
##     3      12 ▇▇▁▁▁▁▁▁
##    34      49 ▂▃▇▆▂▆▃▂
##  1362.5  3500 ▁▃▇▃▁▁▁▁
##     8.75   30 ▇▇▅▂▁▁▁▁
##    44.75  121 ▂▆▇▂▁▁▁▁
##    34.75   75 ▂▅▇▅▁▃▁▂
##    20      50 ▅▇▂▆▁▁▁▁
##     6      30 ▇▇▁▁▁▁▁▁
##   293.75  304 ▇▇▇▇▇▇▇▇
##   320    1270 ▇▆▂▁▁▁▁▁
##    20     290 ▇▁▁▁▁▁▁▁
##   740    2430 ▅▇▃▁▁▁▁▁
##   125     475 ▃▇▂▁▁▁▁▁
##     4       8 ▃▇▇▅▃▂▁▁
##    46     186 ▆▇▁▁▁▁▁▁
##  1780    6080 ▃▇▃▁▁▁▁▁
##    13      87 ▇▅▁▁▁▁▁▁
##    62     156 ▅▆▇▂▁▁▁▁
##    36     141 ▇▇▂▁▁▁▁▁
##    20     180 ▇▁▁▁▁▁▁▂
##    25      70 ▇▃▅▁▁▁▁▁
##    43      57 ▇▇▇▇▇▇▇▇
##   430     900 ▇▅▅▂▂▂▁▁
##    27      40 ▇▇▆▆▂▆▁▃
##   740    1350 ▁▇▇▇▃▁▃▂
##   110     260 ▂▇▅▅▁▁▁▂
##     3       8 ▅▇▂▂▂▁▁▁
##    35      67 ▂▆▃▇▃▁▁▂
##  1550    4520 ▇▇▅▂▁▁▁▁
##     9      17 ▅▃▂▇▃▃▁▁
##    51     126 ▃▇▇▃▁▁▁▁
##    48     100 ▇▆▅▂▂▂▁▁
##    10      20 ▇▂▅▃▁▃▁▁
##     8      25 ▇▅▇▂▁▁▁▁
##   124     137 ▇▇▇▇▇▇▇▇
##   242.5   620 ▇▅▃▂▁▁▁▁
##    60     100 ▆▂▇▂▅▂▂▁
##   740    1160 ▅▇▆▆▅▅▃▂
##    85     190 ▅▇▇▅▃▁▁▁
##    10      16 ▇▇▁▁▆▁▁▁
##    40      78 ▃▇▆▆▃▂▁▁
##  1605    3540 ▃▇▇▆▁▂▂▁
##    14      36 ▇▅▂▃▁▁▁▁
##    92     118 ▇▂▇▂▁▂▇▁
##    26.5    62 ▇▆▂▃▃▁▁▁
##    30      60 ▇▆▅▂▁▁▃▁
##    50     400 ▇▁▁▁▁▁▁▁
##   376.25  400 ▇▇▇▇▇▇▇▇
##   250     380 ▂▇▃▅▆▃▂▂
##    35      45 ▃▃▃▂▂▇▁▁
##   575     880 ▇▅▇▇▇▃▅▁
##    55      85 ▂▂▇▅▃▃▂▂
##     7      17 ▇▇▆▃▂▁▁▁
##    22      37 ▆▇▇▆▆▂▂▁
##  1300    2260 ▇▇▇▇▅▂▂▂
##     5       8 ▅▆▇▇▆▂▃▂
##    64     107 ▇▃▇▆▅▂▂▁
##    28      42 ▂▇▇▆▂▆▃▂
##    15      20 ▂▂▃▁▁▇▁▁
##     6      10 ▁▇▁▇▇▁▃▁
##   486.5   515 ▇▇▇▇▇▇▇▇
## 
## ── Variable type:logical ───────────────────────────────────────────────────────
##   restaurant variable missing complete   n mean                   count
##        Arbys  Chicken       0       55  55 0.24 FAL: 42, TRU: 13, NA: 0
##  Burger King  Chicken       0       70  70 0.49 FAL: 36, TRU: 34, NA: 0
##  Chick Fil-A  Chicken       0       27  27 0.93  TRU: 25, FAL: 2, NA: 0
##  Dairy Queen  Chicken       0       42  42 0.31 FAL: 29, TRU: 13, NA: 0
##    Mcdonalds  Chicken       0       57  57 0.65 TRU: 37, FAL: 20, NA: 0
##        Sonic  Chicken       0       53  53 0.42 FAL: 31, TRU: 22, NA: 0
##       Subway  Chicken       0       96  96 0.17 FAL: 80, TRU: 16, NA: 0
##    Taco Bell  Chicken       0      115 115 0.2  FAL: 92, TRU: 23, NA: 0
## 
## ── Variable type:numeric ───────────────────────────────────────────────────────
##   restaurant     variable missing complete   n   mean   sd    p0  p25  p50
##        Arbys      sat_fat       0       55  55  7.97  4.16 1.5   4.5  7   
##        Arbys Sodium.Grams       0       55  55  1.52  0.66 0.1   0.96 1.48
##        Arbys    trans_fat       0       55  55  0.42  0.59 0     0    0   
##  Burger King      sat_fat       0       70  70 11.15  8.77 2     5    8   
##  Burger King Sodium.Grams       0       70  70  1.22  0.5  0.31  0.85 1.15
##  Burger King    trans_fat       0       70  70  0.86  1.35 0     0    0   
##  Chick Fil-A      sat_fat       0       27  27  4.11  3.9  0     1.5  3   
##  Chick Fil-A Sodium.Grams       0       27  27  1.15  0.73 0.22  0.7  1   
##  Chick Fil-A    trans_fat       0       27  27  0.037 0.19 0     0    0   
##  Dairy Queen      sat_fat       0       42  42 10.44  8.25 0     5    9   
##  Dairy Queen Sodium.Grams       0       42  42  1.18  0.61 0.015 0.85 1.03
##  Dairy Queen    trans_fat       0       42  42  0.68  0.71 0     0    1   
##    Mcdonalds      sat_fat       0       57  57  8.29  5.53 0.5   4.5  7   
##    Mcdonalds Sodium.Grams       0       57  57  1.44  1.04 0.02  0.87 1.12
##    Mcdonalds    trans_fat       0       57  57  0.46  0.72 0     0    0   
##        Sonic      sat_fat       0       53  53 11.42  8.67 2.5   5    8   
##        Sonic Sodium.Grams       0       53  53  1.35  0.67 0.47  0.9  1.25
##        Sonic    trans_fat       0       53  53  0.93  1.26 0     0    0   
##       Subway      sat_fat       0       96  96  6.2   5.24 0     2    4.5 
##       Subway Sodium.Grams       0       96  96  1.27  0.74 0.065 0.7  1.13
##       Subway    trans_fat       0       96  96  0.22  0.52 0     0    0   
##    Taco Bell      sat_fat       0      115 115  6.59  2.98 1     4    6   
##    Taco Bell Sodium.Grams       0      115 115  1.01  0.47 0.29  0.61 0.96
##    Taco Bell    trans_fat       0      115 115  0.26  0.4  0     0    0   
##    p75  p100     hist
##  11    17    ▅▇▆▅▅▃▃▁
##   2.02  3.35 ▁▆▇▅▇▃▁▁
##   1     2    ▇▂▁▂▁▁▁▁
##  13.75 47    ▇▅▁▂▁▁▁▁
##   1.64  2.31 ▅▅▇▅▇▆▃▂
##   1.38  8    ▇▁▁▁▁▁▁▁
##   4.75 16    ▇▇▂▂▁▁▁▂
##   1.41  3.66 ▆▇▇▃▁▁▁▁
##   0     1    ▇▁▁▁▁▁▁▁
##  12.5  43    ▇▇▆▂▂▁▁▁
##   1.36  3.5  ▁▃▇▃▁▁▁▁
##   1     2    ▇▁▁▇▁▁▁▂
##  11    27    ▃▇▅▃▂▁▁▁
##   1.78  6.08 ▃▇▃▁▁▁▁▁
##   1     3    ▇▂▁▂▁▁▁▁
##  15    36    ▇▇▃▂▁▁▁▂
##   1.55  4.52 ▇▇▅▂▁▁▁▁
##   2     4    ▇▂▁▂▁▁▁▁
##   9.25 22    ▇▅▃▃▂▁▁▁
##   1.61  3.54 ▃▇▇▆▁▂▂▁
##   0     2    ▇▁▁▁▁▁▁▁
##   9    14    ▂▇▆▆▆▃▃▁
##   1.3   2.26 ▇▇▇▇▅▂▂▂
##   0.5   1    ▇▁▁▂▁▁▁▂
FastFood %>% group_by(restaurant) %>% summarise(Mean.Prot = mean(protein), Mean.Protein.NA = mean(protein, na.rm=TRUE))
## # A tibble: 8 x 3
##   restaurant  Mean.Prot Mean.Protein.NA
## * <chr>           <dbl>           <dbl>
## 1 Arbys            29.3            29.3
## 2 Burger King      NA              30.0
## 3 Chick Fil-A      31.7            31.7
## 4 Dairy Queen      24.8            24.8
## 5 Mcdonalds        40.3            40.3
## 6 Sonic            29.2            29.2
## 7 Subway           30.3            30.3
## 8 Taco Bell        17.4            17.4
# Helpful for specific skim() on functions
FastFood %>% group_by(restaurant, Chicken) %>% skim(Sodium.Grams)
## Skim summary statistics
##  n obs: 515 
##  n variables: 20 
##  group variables: restaurant, Chicken 
## 
## ── Variable type:numeric ───────────────────────────────────────────────────────
##   restaurant Chicken     variable missing complete  n mean   sd    p0  p25  p50
##        Arbys   FALSE Sodium.Grams       0       42 42 1.57 0.7  0.1   0.99 1.52
##        Arbys    TRUE Sodium.Grams       0       13 13 1.33 0.52 0.64  0.95 1.21
##  Burger King   FALSE Sodium.Grams       0       36 36 1.21 0.5  0.45  0.8  1.16
##  Burger King    TRUE Sodium.Grams       0       34 34 1.24 0.5  0.31  0.85 1.15
##  Chick Fil-A   FALSE Sodium.Grams       0        2  2 1.48 0.4  1.2   1.34 1.48
##  Chick Fil-A    TRUE Sodium.Grams       0       25 25 1.13 0.75 0.22  0.67 0.99
##  Dairy Queen   FALSE Sodium.Grams       0       29 29 1.08 0.46 0.015 0.9  1   
##  Dairy Queen    TRUE Sodium.Grams       0       13 13 1.41 0.84 0.67  0.82 1.19
##    Mcdonalds   FALSE Sodium.Grams       0       20 20 1.31 0.9  0.48  0.83 1.02
##    Mcdonalds    TRUE Sodium.Grams       0       37 37 1.51 1.11 0.02  0.96 1.19
##        Sonic   FALSE Sodium.Grams       0       31 31 1.19 0.42 0.47  0.86 1.18
##        Sonic    TRUE Sodium.Grams       0       22 22 1.58 0.87 0.67  0.97 1.42
##       Subway   FALSE Sodium.Grams       0       80 80 1.3  0.77 0.065 0.72 1.19
##       Subway    TRUE Sodium.Grams       0       16 16 1.15 0.6  0.28  0.66 1.08
##    Taco Bell   FALSE Sodium.Grams       0       92 92 0.98 0.46 0.29  0.59 0.93
##    Taco Bell    TRUE Sodium.Grams       0       23 23 1.15 0.52 0.46  0.74 1.07
##   p75 p100     hist
##  2.09 3.35 ▁▆▇▆▇▅▁▁
##  1.75 2.11 ▃▇▁▂▂▂▂▆
##  1.58 2.27 ▇▅▇▆▆▃▅▂
##  1.64 2.31 ▂▇▇▇▇▇▂▂
##  1.62 1.76 ▇▁▁▁▁▁▁▇
##  1.35 3.66 ▆▇▆▃▁▁▁▁
##  1.25 2.21 ▁▂▃▇▅▃▁▂
##  1.53 3.5  ▇▅▅▁▁▂▁▂
##  1.38 4.45 ▇▅▂▁▁▁▁▁
##  1.82 6.08 ▃▇▅▁▂▁▁▁
##  1.41 2.31 ▃▇▆▇▆▂▁▁
##  2.02 4.52 ▇▅▂▂▁▁▁▁
##  1.61 3.54 ▃▇▇▆▁▂▂▁
##  1.41 2.28 ▃▅▂▇▂▁▃▃
##  1.27 2.26 ▇▇▇▇▅▂▁▂
##  1.5  2.23 ▇▂▇▂▅▁▂▁

Summarize

FastFood %>% 
  group_by(restaurant, Chicken) %>% 
  summarise(Mean.Protein = mean(protein),
            Mean.Protein.NA = mean(protein, na.rm=TRUE))
## # A tibble: 16 x 4
## # Groups:   restaurant [8]
##    restaurant  Chicken Mean.Protein Mean.Protein.NA
##    <chr>       <lgl>          <dbl>           <dbl>
##  1 Arbys       FALSE           29.6            29.6
##  2 Arbys       TRUE            28              28  
##  3 Burger King FALSE           NA              34.1
##  4 Burger King TRUE            25.8            25.8
##  5 Chick Fil-A FALSE           33.5            33.5
##  6 Chick Fil-A TRUE            31.6            31.6
##  7 Dairy Queen FALSE           23.3            23.3
##  8 Dairy Queen TRUE            28.3            28.3
##  9 Mcdonalds   FALSE           36.2            36.2
## 10 Mcdonalds   TRUE            42.5            42.5
## 11 Sonic       FALSE           28.9            28.9
## 12 Sonic       TRUE            29.5            29.5
## 13 Subway      FALSE           28.7            28.7
## 14 Subway      TRUE            38.4            38.4
## 15 Taco Bell   FALSE           16.4            16.4
## 16 Taco Bell   TRUE            21.3            21.3

Ungroup

FastFood %>% 
  group_by(restaurant) %>% 
  mutate(Avg.Protein = mean(protein, na.rm=TRUE),
         Protein.Dev = protein - Avg.Protein)
## # A tibble: 515 x 22
## # Groups:   restaurant [8]
##    restaurant Sodium.Grams sodium    X1 item  calories cal_fat total_fat sat_fat
##    <chr>             <dbl>  <int> <int> <chr>    <int>   <int>     <int>   <dbl>
##  1 Mcdonalds          1.11   1110     1 Arti…      380      60         7       2
##  2 Mcdonalds          1.58   1580     2 Sing…      840     410        45      17
##  3 Mcdonalds          1.92   1920     3 Doub…     1130     600        67      27
##  4 Mcdonalds          1.94   1940     4 Gril…      750     280        31      10
##  5 Mcdonalds          1.98   1980     5 Cris…      920     410        45      12
##  6 Mcdonalds          0.95    950     6 Big …      540     250        28      10
##  7 Mcdonalds          0.68    680     7 Chee…      300     100        12       5
##  8 Mcdonalds          1.04   1040     8 Clas…      510     210        24       4
##  9 Mcdonalds          1.04   1040     9 Doub…      430     190        21      11
## 10 Mcdonalds          1.29   1290    10 Doub…      770     400        45      21
## # … with 505 more rows, and 13 more variables: trans_fat <dbl>,
## #   cholesterol <int>, total_carb <int>, fiber <int>, sugar <int>,
## #   protein <int>, vit_a <int>, vit_c <int>, calcium <int>, salad <chr>,
## #   Chicken <lgl>, Avg.Protein <dbl>, Protein.Dev <dbl>
FastFood %>% 
  group_by(restaurant) %>% 
  mutate(Avg.Protein = mean(protein, na.rm=TRUE),
         Protein.Dev = protein - Avg.Protein) %>%
  ungroup()
## # A tibble: 515 x 22
##    restaurant Sodium.Grams sodium    X1 item  calories cal_fat total_fat sat_fat
##    <chr>             <dbl>  <int> <int> <chr>    <int>   <int>     <int>   <dbl>
##  1 Mcdonalds          1.11   1110     1 Arti…      380      60         7       2
##  2 Mcdonalds          1.58   1580     2 Sing…      840     410        45      17
##  3 Mcdonalds          1.92   1920     3 Doub…     1130     600        67      27
##  4 Mcdonalds          1.94   1940     4 Gril…      750     280        31      10
##  5 Mcdonalds          1.98   1980     5 Cris…      920     410        45      12
##  6 Mcdonalds          0.95    950     6 Big …      540     250        28      10
##  7 Mcdonalds          0.68    680     7 Chee…      300     100        12       5
##  8 Mcdonalds          1.04   1040     8 Clas…      510     210        24       4
##  9 Mcdonalds          1.04   1040     9 Doub…      430     190        21      11
## 10 Mcdonalds          1.29   1290    10 Doub…      770     400        45      21
## # … with 505 more rows, and 13 more variables: trans_fat <dbl>,
## #   cholesterol <int>, total_carb <int>, fiber <int>, sugar <int>,
## #   protein <int>, vit_a <int>, vit_c <int>, calcium <int>, salad <chr>,
## #   Chicken <lgl>, Avg.Protein <dbl>, Protein.Dev <dbl>

Counts

( Restaurant.Table <- FastFood %>% group_by(restaurant) %>% summarise(Count = n()) %>% arrange(Count) )
## # A tibble: 8 x 2
##   restaurant  Count
##   <chr>       <int>
## 1 Chick Fil-A    27
## 2 Dairy Queen    42
## 3 Sonic          53
## 4 Arbys          55
## 5 Mcdonalds      57
## 6 Burger King    70
## 7 Subway         96
## 8 Taco Bell     115