본문 바로가기

R프로그래밍,통계학

남자 나이대별 폰 사용 비율

반응형
#mage 변수 만들기#
mage <- mprofile$X0004
str(mage)
#View(age)
mage[mage=='1']<-'1318'
mage[mage=='2']<-'1924'
mage[mage=='3']<-'2534'
mage[mage=='4']<-'3544'
mage[mage=='5']<-'45'
table(mage)  #나이대  
plot(table(mage))
#mphone 변수 만들기#
# 1,2.
mprofile$mphone <- ifelse(mprofile$J0081 ==1,"아이폰",ifelse(mprofile$J0080==1,"엘지",ifelse(mprofile$J0079==1,"삼성","기타")))
attach(mprofile)
View(head(mphone))

View(table(mphone,mskin_mean))
plot(table(mphone, mage))

별거는 없는거같은데... 젊은층 아이폰사용비율이 높게 나오는걸 볼 수있다.

 


##ggplot으로 좀 더 세련되게
  
barplot(table(mage))

class(table(mage))

table(mage)
a <-as.data.frame(table(mage))
a

rownames(a)
a$mage <- rownames(a)
rownames(a) <- NULL
a

ggplot(a, aes(x=mage,y=Freq))+geom_bar(stat="identity")+scale_fill_brewer()

#b 도 해보자. 폰도 추가해서!

b <- as.data.frame(table(mphone,mage))
b

ggplot(b, aes(x=mage,y=Freq,fill=mphone))+geom_bar(stat="identity")+scale_fill_brewer()

 

 

 

 

 

 

 

 

 

 

반응형

'R프로그래밍,통계학' 카테고리의 다른 글

R완전 삭제하고 제대로 다시 설치하기!  (0) 2020.07.26
R(studio)버전확인  (0) 2020.07.25
0324.  (0) 2020.07.23
빅데이터 공모전 복습 0317  (0) 2020.07.23
빅데이터 공모전 복습 0316, 0321  (0) 2020.07.23