NonCompart - Long format

2017/09/21

Categories: R Tags: R NCA

NonCompart 패키지의 tblNCA()함수를 사용해서 비구획분석 결과를 내면 문자형식의 행렬이 생성되고 그 attr로 dimnamesunits를 갖는데 이를 long format의 tidy data로 변환하는 방법은 다음과 같습니다.

library(dplyr)
library(tidyr)
library(NonCompart)

먼저 위와 같은 패키지가 설치되어 있어야 합니다.

ncares <- NonCompart::tblNCA(Theoph, key="Subject", dose=320, concUnit="mg/L")
str(ncares)
##  chr [1:12, 1:37] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:37] "Subject" "b0" "CMAX" "CMAXD" ...
##  - attr(*, "units")= chr [1:37] "" "" "mg/L" "mg/L/mg" ...
left_join(as_tibble(ncares) %>% gather(PPTESTCD, PPORRES, -Subject),
          tibble(PPTESTCD = attr(ncares, 'dimnames')[[2]], UNIT = attr(ncares, 'units')),
          by = 'PPTESTCD') %>% 
  arrange(Subject, PPTESTCD) %>% 
  head(20)
Subject PPTESTCD PPORRES UNIT
1 AUCALL 148.92305 h*mg/L
1 AUCIFO 216.611933038226 h*mg/L
1 AUCIFOD 0.676912290744456 h*mg/L/mg
1 AUCIFP 216.614955803818 h*mg/L
1 AUCIFPD 0.67692173688693 h*mg/L/mg
1 AUCLST 148.92305 h*mg/L
1 AUCPEO 31.2489169404534 %
1 AUCPEP 31.2498763313113 %
1 AUMCIFO 4505.53481941065 h2*mg/L
1 AUMCIFP 4505.67086458209 h2*mg/L
1 AUMCLST 1459.0711035 h2*mg/L
1 AUMCPEO 67.6160286851172 %
1 AUMCPEP 67.6170064935417 %
1 b0 2.36878509420585
1 CLFO 1.47729626669981 L/h
1 CLFP 1.47727565168591 L/h
1 CLST 3.28 mg/L
1 CLSTP 3.28014647414312 mg/L
1 CMAX 10.5 mg/L
1 CMAXD 0.0328125 mg/L/mg

Reference