>RE::VISION CRM

R 데이터 분석

Reshape 샘플

YONG_X 2015. 6. 29. 16:01


actor <- c("kim", "lee", "hyun")
gender <- c("M", "F", "M")
boxoffice2012 <- c(100, 110, 120)
boxoffice2014 <- c(100, 80, 160)
actordf <- data.frame(actor, gender,boxoffice2012, boxoffice2014) 

actordft <- t(actordf)
actordft 
str(actordft )

require(reshape)

# gender 가없었을때 돌아가던 것
actordf_m1 <- melt(actordf, id=c("actor"))
actordf_m1

gender 가 추가된 후 ... 
actordf_m2 <- melt(actordf, id=c("gender", "actor"))
actordf_m2

actordf_m2$variable <- substr(actordf_m2$variable, 10, 13)
names(actordf_m2)[3] <- "boyear"
names(actordf_m2)[4] <- "boxoffice"


cast(actordf_m2, boyear ~ actor, mean, value = 'boxoffice')

cast(actordf_m2, actor ~ boyear, mean, value = 'boxoffice')

cast(actordf_m2, actor ~ boyear, sum, value = 'boxoffice')

cast(actordf_m2, actor ~ boyear, sum, value = 'boxoffice')


cast(actordf_m2, gender ~ boyear, mean, value = 'boxoffice')


'R 데이터 분석' 카테고리의 다른 글

[R and SQL] [0630 ...................]  (0) 2015.06.30
추가 0629  (0) 2015.06.29
경기도 버스 : 경기도교통정보센터  (0) 2015.06.29
GT apple samsung applications  (0) 2015.06.29
애플과 삼성 구글트렌드 값 비교  (0) 2015.06.29