Day1 - tidyverse | 2023-09-01
Jinhwan Kim
The Treachery of Images
This is not Pipe
르네 마그리트 (René Magritte)
Pipe Operator %>%, |>
|>
(native pipe)는 magrittr 없이도 R 4.1 이상에서 사용 가능. 아직은 %>%
가 |>
에 비해 조금 더 다양한 기능 지원
EXMD_BZ_YYYY RN_INDI HME_YYYYMM Q_PHX_DX_STK Q_PHX_DX_HTDZ Q_PHX_DX_HTN
1 2009 562083 200909 0 0 1
2 2009 334536 200911 0 0 0
3 2009 911867 200903 0 0 0
4 2009 183321 200908 NA NA NA
Q_PHX_DX_DM Q_PHX_DX_DLD Q_PHX_DX_PTB Q_HBV_AG Q_SMK_YN Q_DRK_FRQ_V09N HGHT
1 0 0 NA 3 1 0 144
2 0 0 NA 2 1 0 162
3 0 0 NA 3 1 0 163
4 NA NA NA 3 1 0 152
WGHT WSTC BMI VA_LT VA_RT BP_SYS BP_DIA URN_PROT HGB FBS TOT_CHOL TG HDL LDL
1 61 90 29 1 1 120 80 1 13 117 264 128 60 179
2 51 63 19 1 1 120 80 1 14 96 169 92 70 80
3 65 82 25 1 1 130 80 1 15 118 216 132 55 134
4 51 70 22 1 1 101 62 1 13 90 199 100 65 114
CRTN SGOT SGPT GGT GFR
1 1 25 20 25 59
2 1 18 15 28 74
3 1 26 30 30 79
4 1 18 14 11 61
EXMD_BZ_YYYY RN_INDI HME_YYYYMM Q_PHX_DX_STK Q_PHX_DX_HTDZ Q_PHX_DX_HTN
215 2010 383603 201012 NA NA NA
216 2010 326432 201012 NA NA NA
217 2010 915731 201005 NA NA NA
218 2010 793017 201006 NA NA NA
Q_PHX_DX_DM Q_PHX_DX_DLD Q_PHX_DX_PTB Q_HBV_AG Q_SMK_YN Q_DRK_FRQ_V09N HGHT
215 NA NA NA 3 1 0 172
216 NA NA NA 2 1 0 160
217 NA NA NA 3 1 0 170
218 NA NA NA 2 1 0 156
WGHT WSTC BMI VA_LT VA_RT BP_SYS BP_DIA URN_PROT HGB FBS TOT_CHOL TG HDL
215 58 68 20 2 2 126 78 1 13 98 254 47 77
216 54 69 21 1 1 120 80 1 13 100 226 94 70
217 63 83 22 2 1 140 90 1 15 94 150 76 69
218 53 69 22 1 1 128 83 1 11 100 150 114 43
LDL CRTN SGOT SGPT GGT GFR
215 167 1 27 27 36 NA
216 137 1 21 17 10 NA
217 65 1 16 19 43 NA
218 84 1 19 22 38 NA
EXMD_BZ_YYYY RN_INDI HME_YYYYMM Q_PHX_DX_STK Q_PHX_DX_HTDZ Q_PHX_DX_HTN
215 2010 383603 201012 NA NA NA
217 2010 915731 201005 NA NA NA
218 2010 793017 201006 NA NA NA
227 2010 752655 201001 NA NA NA
Q_PHX_DX_DM Q_PHX_DX_DLD Q_PHX_DX_PTB Q_HBV_AG Q_SMK_YN Q_DRK_FRQ_V09N HGHT
215 NA NA NA 3 1 0 172
217 NA NA NA 3 1 0 170
218 NA NA NA 2 1 0 156
227 NA NA NA 3 1 0 166
WGHT WSTC BMI VA_LT VA_RT BP_SYS BP_DIA URN_PROT HGB FBS TOT_CHOL TG HDL
215 58 68 20 2 2 126 78 1 13 98 254 47 77
217 63 83 22 2 1 140 90 1 15 94 150 76 69
218 53 69 22 1 1 128 83 1 11 100 150 114 43
227 76 86 28 2 10 120 80 1 15 91 148 150 68
LDL CRTN SGOT SGPT GGT GFR
215 167 1 27 27 36 NA
217 65 1 16 19 43 NA
218 84 1 19 22 38 NA
227 50 1 31 39 33 NA
(Intercept) HGB
172.9083 1.5375
Q_SMK_YN EXMD_BZ_YYYY RN_INDI HME_YYYYMM Q_PHX_DX_STK Q_PHX_DX_HTDZ
1 1 2013.5 467320.3 201358.6 0 0
2 2 2013.5 482871.8 201357.0 0 0
3 3 2013.5 516423.4 201356.9 0 0
Q_PHX_DX_HTN Q_PHX_DX_DM Q_PHX_DX_DLD Q_PHX_DX_PTB Q_HBV_AG Q_DRK_FRQ_V09N
1 0.2 0.0 0.0 0 2.2 0.6
2 0.2 0.1 0.1 0 2.1 1.4
3 0.1 0.0 0.0 0 2.3 1.8
HGHT WGHT WSTC BMI VA_LT VA_RT BP_SYS BP_DIA URN_PROT HGB FBS TOT_CHOL
1 161.9 62.6 78.7 23.8 1.0 1.0 121.0 75.7 1.1 13.7 96.6 195.6
2 169.8 70.8 84.5 24.6 1.1 1.1 124.7 78.7 1.1 15.0 99.8 193.0
3 172.4 72.8 84.1 24.5 1.2 1.2 122.3 76.8 1.1 15.5 96.5 196.7
TG HDL LDL CRTN SGOT SGPT GGT GFR
1 114.4 57.3 115.8 1 23.6 22.1 27.6 90.0
2 157.1 50.8 112.4 1 27.3 29.4 42.3 86.7
3 167.7 51.6 120.5 1 25.4 28.9 48.4 93.3
HINT: sutset(select = EXMD_BZ_YYYY)
사용
Pipe를 사용하는 것으로
ex1.2012
, ex1
사용 Xex
)magrittr는 코드의 가독성을 위한 Pipe operator, %>%를 쓸 수 있게 하는 패키지
Pipe는 Functional Programming
, Tidyverse
에서의 핵심
프로그래밍 퍼포먼스의 관점에서 %T>%, %$%, %<>%, %!>%등 다양한 Pipe도 있지만 몰라도 무방
더 자세한 내용은 Introducing magrittr 아티클 참조