data.table 녹이기

R의 data.table로 데이터 결합하기

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

와이드 data.table 녹이기

R의 data.table로 데이터 결합하기

`melt()` 함수

measure.vars로 쌓을 열을 지정합니다:

melt(sales_wide, measure.vars = c("2015", "2016"))
   quarter variable   value
1:       1     2015 3200100
2:       2     2015 2950000
3:       3     2015 2980700
4:       4     2015 3420000
5:       1     2016 3350000
6:       2     2016 3000300
7:       3     2016 3120200
8:       4     2016 3670000
R의 data.table로 데이터 결합하기

`melt()` 함수

variable.namevalue.name으로 결과 열 이름을 변경합니다:

melt(sales_wide, measure.vars = c("2015", "2016"), 
     variable.name = "year", value.name = "amount")
   quarter year  amount
1:       1 2015 3200100
2:       2 2015 2950000
3:       3 2015 2980700
4:       4 2015 3420000
5:       1 2016 3350000
6:       2 2016 3000300
7:       3 2016 3120200
8:       4 2016 3670000
R의 data.table로 데이터 결합하기

`melt()` 함수

id.vars로 유지할 열을 지정합니다

melt(sales_wide, id.vars = "quarter", 
     variable.name = "year", value.name = "amount")
   quarter year  amount
1:       1 2015 3200100
2:       2 2015 2950000
3:       3 2015 2980700
4:       4 2015 3420000
5:       1 2016 3350000
6:       2 2016 3000300
7:       3 2016 3120200
8:       4 2016 3670000
R의 data.table로 데이터 결합하기

`melt()` 함수

두 인수를 함께 사용하여 열의 일부만 유지합니다

melt(sales_wide, id.vars = "quarter", measure.vars = "2015", 
     variable.name = "year", value.name = "amount")
   quarter year  amount
1:       1 2015 3200100
2:       2 2015 2950000
3:       3 2015 2980700
4:       4 2015 3420000
R의 data.table로 데이터 결합하기

연습해 봅시다!

R의 data.table로 데이터 결합하기

Preparing Video For Download...