Following the in-class assignment this week, perform a complete RCBD analysis.
library(erikmisc)
library(tidyverse)
# read the data
<- read.table(text="
dat_food Restaurant Item1 Item2 Item3
A 31 27 24
B 31 28 31
C 45 29 46
D 21 18 48
E 42 36 46
F 32 17 40
", header = TRUE) %>%
as_tibble()
The code below will get you started with reshaping the data. The rest is up to you!
<-
dat_food_long %>%
dat_food pivot_longer(
cols = starts_with("Item")
names_to = "Item"
, values_to = "Sales"
, %>%
) mutate(
Item = factor(Item)
Restaurant = factor(Restaurant)
,
)
str(dat_food_long)
tibble [18 x 3] (S3: tbl_df/tbl/data.frame)
$ Restaurant: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 2 2 2 3 3 3 4 ...
$ Item : Factor w/ 3 levels "Item1","Item2",..: 1 2 3 1 2 3 1 2 3 1 ...
$ Sales : int [1:18] 31 27 24 31 28 31 45 29 46 21 ...
# Group means
<-
m_dat_b %>%
dat_food_long group_by(Item) %>%
summarize(
m = mean(Sales)
) m_dat_b
# A tibble: 3 x 2
Item m
<fct> <dbl>
1 Item1 33.7
2 Item2 25.8
3 Item3 39.2
<-
m_dat_c %>%
dat_food_long group_by(Restaurant) %>%
summarize(
m = mean(Sales)
) m_dat_c
# A tibble: 6 x 2
Restaurant m
<fct> <dbl>
1 A 27.3
2 B 30
3 C 40
4 D 29
5 E 41.3
6 F 29.7