###類別資料分析__男女對顏色的喜好的差異?
#下載資料:https://www.kaggle.com/hb20007/gender-classification?select=Transformed+Data+Set+-+Sheet1.csv
#檔名為"Transformed Data Set - Sheet1.csv"
#從電腦端上傳(upload)到rstudio cloud
library(readr)
#讀取資料,命名為"x"
x <- read.csv("Transformed Data Set - Sheet1.csv")
#查看資料結構
summary(x)
## Favorite.Color Favorite.Music.Genre Favorite.Beverage
## Cool :37 Electronic : 8 Beer :13
## Neutral: 7 Folk/Traditional: 4 Doesn't drink:14
## Warm :22 Hip hop : 8 Other :11
## Jazz/Blues : 4 Vodka : 9
## Pop :17 Whiskey : 9
## R&B and soul : 6 Wine :10
## Rock :19
## Favorite.Soft.Drink Gender
## 7UP/Sprite :13 F:33
## Coca Cola/Pepsi:32 M:33
## Fanta :14
## Other : 7
##
##
##
#重新命名欄位名稱
colnames(x) <- c("color", "music", "beverage", "drink", "gender")
#問題:男女對顏色的喜好的差異?
#次數分配表
t <- table(x$gender,x$color)
t
##
## Cool Neutral Warm
## F 17 3 13
## M 20 4 9
#百分比次數分配表
p.t <- prop.table(t)
p.t <- round(p.t*100,2)
p.t
##
## Cool Neutral Warm
## F 25.76 4.55 19.70
## M 30.30 6.06 13.64
#畫分組長條圖
barplot(p.t)

barplot(p.t, beside = TRUE)
