R
[R] reshape2::melt,dcast
ㄷㅐ장님
2022. 1. 26. 14:00
install.packages("reshape2")
library(reshape2)
reshape2::melt(데이터,id='기준')
: 컬럼이 많은 형태(wide)를 세로방향으로 긴(long) 형태로 변경하는 함수
기본데이터
reshape2::melt(fruits,id='year')
reshape2::melt(fruit,id=c('year','name'))
reshape2::dcast(데이터,행~열)
: long(세로)을 wide(가로) 형태로 변경하는 함수
m<-melt(fruit,id=c('year','name'))
dcast(m,year+name~variable)
dcast(m,name~variable,sum)
=
library(dplyr)
fruits %>%
dplyr::group_by(year)%>%
dplyr::summarise(qty=sum(qty),price=sum(price))
dcast(m,year~variable,sum)