연세대학교 비즈니스 애널리틱스 수업자료를 토대로 한 복습 자료입니다.
Load the .csv data from the web
seg.df = read.csv("http://goo.gl/qw303p")
summary(seg.df)
## age gender income kids ownHome
## Min. :19.26 Female:157 Min. : -5183 Min. :0.00 ownNo :159
## 1st Qu.:33.01 Male :143 1st Qu.: 39656 1st Qu.:0.00 ownYes:141
## Median :39.49 Median : 52014 Median :1.00
## Mean :41.20 Mean : 50937 Mean :1.27
## 3rd Qu.:47.90 3rd Qu.: 61403 3rd Qu.:2.00
## Max. :80.49 Max. :114278 Max. :7.00
## subscribe Segment
## subNo :260 Moving up : 70
## subYes: 40 Suburb mix:100
## Travelers : 80
## Urban hip : 50
##
##
Explore the data structure
str(seg.df)
## 'data.frame': 300 obs. of 7 variables:
## $ age : num 47.3 31.4 43.2 37.3 41 ...
## $ gender : Factor w/ 2 levels "Female","Male": 2 2 2 1 1 2 2 2 1 1 ...
## $ income : num 49483 35546 44169 81042 79353 ...
## $ kids : int 2 1 0 1 3 4 3 0 1 0 ...
## $ ownHome : Factor w/ 2 levels "ownNo","ownYes": 1 2 2 1 2 2 1 1 1 2 ...
## $ subscribe: Factor w/ 2 levels "subNo","subYes": 1 1 1 1 1 1 1 1 1 1 ...
## $ Segment : Factor w/ 4 levels "Moving up","Suburb mix",..: 2 2 2 2 2 2 2 2 2 2 ...
head(seg.df)
## age gender income kids ownHome subscribe Segment
## 1 47.31613 Male 49482.81 2 ownNo subNo Suburb mix
## 2 31.38684 Male 35546.29 1 ownYes subNo Suburb mix
## 3 43.20034 Male 44169.19 0 ownYes subNo Suburb mix
## 4 37.31700 Female 81041.99 1 ownNo subNo Suburb mix
## 5 40.95439 Female 79353.01 3 ownYes subNo Suburb mix
## 6 43.03387 Male 58143.36 4 ownYes subNo Suburb mix
summary(seg.df)
## age gender income kids ownHome
## Min. :19.26 Female:157 Min. : -5183 Min. :0.00 ownNo :159
## 1st Qu.:33.01 Male :143 1st Qu.: 39656 1st Qu.:0.00 ownYes:141
## Median :39.49 Median : 52014 Median :1.00
## Mean :41.20 Mean : 50937 Mean :1.27
## 3rd Qu.:47.90 3rd Qu.: 61403 3rd Qu.:2.00
## Max. :80.49 Max. :114278 Max. :7.00
## subscribe Segment
## subNo :260 Moving up : 70
## subYes: 40 Suburb mix:100
## Travelers : 80
## Urban hip : 50
##
##
# loading the lattice package
library(lattice)
library(ggplot2)
ggplot(seg.df, aes(x = Segment, fill = subscribe))+
geom_bar()+
labs(
y= ""
)