자격증/ADsP 03 데이터 분석

R 데이터 마트 - reshape 실습

momong'-' 2020. 2. 9. 23:09
  • 주석: #006DD7
  • 코드입력: #333333
  • 결과값: #9D9D9D

 

  • reshape 패키지

melt(): 원데이터 형태로 만드는 함수

cast(): 요약 형태로 만드는 함수

 

  • reshape 패키지 설치 방법

install.packages("reshape")

install.packages("reshape") 입력 후 엔터
korea 선택 후 OK 클릭 후 다운로드 시작

 

reshape 설치 완료

> library(reshape)

> head(airquality)
  Ozone Solar.R Wind Temp Month Day
1    41     190  7.4   67     5   1
2    36     118  8.0   72     5   2
3    12     149 12.6   74     5   3
4    18     313 11.5   62     5   4
5    NA      NA 14.3   56     5   5
6    28      NA 14.9   66     5   6


> melt(airquality, id=c("Month", "Day"), na.rm=T)
    Month Day variable value
1       5   1    Ozone  41.0
2       5   2    Ozone  36.0
3       5   3    Ozone  12.0
4       5   4    Ozone  18.0
5       5   6    Ozone  28.0
6       5   7    Ozone  23.0
···
563     9  25     Temp  63.0
564     9  26     Temp  70.0
565     9  27     Temp  77.0
566     9  28     Temp  75.0
567     9  29     Temp  76.0
568     9  30     Temp  68.0