library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(memisc)
## Loading required package: lattice
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## Attaching package: 'memisc'
## The following objects are masked from 'package:dplyr':
##
## collect, recode, rename, syms
## The following objects are masked from 'package:stats':
##
## contr.sum, contr.treatment, contrasts
## The following object is masked from 'package:base':
##
## as.array
library(stringr)
#candy <- read.csv("https://raw.githubusercontent.com/mkollontai/DATA607/master/candyhierarchy2017.csv")
candy <- read.csv("candyhierarchy2017.csv")
#Create subsets of data from respondends who identified their gender as 'Male' or 'Female' and only focuses on the data for 4 very popular candy brands - Twix, Starburst, Snickers, and Skittles.
MCandy <- candy %>%
filter(Q2..GENDER == "Male") %>%
dplyr::select(c("Q3..AGE","Q6...Twix","Q6...Starburst","Q6...Snickers","Q6...Skittles"))
MTwixCount <- count(MCandy,Q6...Twix)
MStarCount <- count(MCandy,Q6...Starburst)
MSnickCount <- count(MCandy,Q6...Snickers)
MSkittCount <- count(MCandy,Q6...Skittles)
MC_Summary <- bind_cols(MTwixCount,MStarCount[2],MSnickCount[2],MSkittCount[2])
names(MC_Summary) <- c("Feels","Twix","Starburst","Snickers","Skittles")
MC_Summary
## # A tibble: 4 x 5
## Feels Twix Starburst Snickers Skittles
## <fct> <int> <int> <int> <int>
## 1 "" 401 403 403 414
## 2 DESPAIR 45 190 45 187
## 3 JOY 842 500 852 492
## 4 MEH 179 374 167 374
FCandy <- candy %>%
filter(Q2..GENDER == "Female") %>%
dplyr::select(c("Q3..AGE","Q6...Twix","Q6...Starburst","Q6...Snickers","Q6...Skittles"))
FTwixCount <- count(FCandy,Q6...Twix)
FStarCount <- count(FCandy,Q6...Starburst)
FSnickCount <- count(FCandy,Q6...Snickers)
FSkittCount <- count(FCandy,Q6...Skittles)
FC_Summary <- bind_cols(FTwixCount,FStarCount[2],FSnickCount[2],FSkittCount[2])
names(FC_Summary) <- c("Feels","Twix","Starburst","Snickers","Skittles")
FC_Summary
## # A tibble: 4 x 5
## Feels Twix Starburst Snickers Skittles
## <fct> <int> <int> <int> <int>
## 1 "" 229 231 230 232
## 2 DESPAIR 22 89 29 114
## 3 JOY 498 307 474 293
## 4 MEH 90 212 106 200
```