Data Manipulation
twoway_data%>%
gather(key = Plot, value = Yield, -c(Fertilizer,Manure)) %>%
mutate(across(Fertilizer:Plot, ~ as.factor(.x))) -> clean_twoway_data
# Structure preview
str(clean_twoway_data)
## tibble [20 x 4] (S3: tbl_df/tbl/data.frame)
## $ Fertilizer: Factor w/ 2 levels "High","Low": 1 1 2 2 1 1 2 2 1 1 ...
## $ Manure : Factor w/ 2 levels "High","Low": 1 2 1 2 1 2 1 2 1 2 ...
## $ Plot : Factor w/ 5 levels "P1","P2","P3",..: 1 1 1 1 2 2 2 2 3 3 ...
## $ Yield : num [1:20] 13.7 16.4 15 12.4 15.8 12.5 15.1 10.6 13.9 14.1 ...
# Sample preview
clean_twoway_data %>%
sample_n(10)
## # A tibble: 10 x 4
## Fertilizer Manure Plot Yield
## <fct> <fct> <fct> <dbl>
## 1 High High P3 13.9
## 2 Low Low P5 10.9
## 3 High High P2 15.8
## 4 High Low P4 14.4
## 5 High High P5 15.5
## 6 High Low P2 12.5
## 7 Low High P3 12
## 8 High High P1 13.7
## 9 High Low P3 14.1
## 10 Low Low P3 13.7