楼主: verbatim
1721 6

[问答] thanks for help with R code to duplicate the dosing record with EVID=1 [推广有奖]

  • 1关注
  • 3粉丝

已卖:25份资源

博士生

5%

还不是VIP/贵宾

-

威望
0
论坛币
513 个
通用积分
2.0505
学术水平
0 点
热心指数
2 点
信用等级
0 点
经验
3404 点
帖子
139
精华
0
在线时间
143 小时
注册时间
2006-12-1
最后登录
2020-1-30

楼主
verbatim 发表于 2011-12-3 01:31:27 |AI写论文
30论坛币
thanks for help with R code to duplicate the dosing record with EVID=1 for each ID in below sample dataset.

STUD ID SUBJ TIME AMT DV MDV EVID SS II DOSE AGE NSEX NRACE HT WT
1 1 10001 -0.483 . 0 0 0 2 21 0 180 64.5
1 1 10001 0 2 . 1 1 0 0 2 21 0 180 64.5
1 1 10001 0.6 . 0 0 0 . . 2 21 0 180 64.5
1 1 10001 1.1 . 3.192 0 0 . . 2 21 0 180 64.5
1 1 10001 1.52 . 6.184 0 0 . . 2 21 0 180 64.5
1 1 10001 2.12 . 7.723 0 0 . . 2 21 0 180 64.5
1 1 10001 2.5 . 7.59 0 0 . . 2 21 0 180 64.5
1 1 10001 3.1 . 8.063 0 0 . . 2 21 0 180 64.5
1 1 10001 4.1 . 8.018 0 0 . . 2 21 0 180 64.5
1 1 10001 6.12 . 7.652 0 0 . . 2 21 0 180 64.5
1 1 10001 12.35 . 4.616 0 0 . . 2 21 0 180 64.5
1 1 10001 24.1 . 1.209 0 0 . . 2 21 0 180 64.5
1 1 10001 48 . 0 0 0 2 21 0 180 64.5
1 1 10001 72 . 0 0 0 2 21 0 180 64.5
2 30 20404 -2.6 . . 1 0 2 47 0 2 168 65
2 30 20404 0 2 . 1 1 0 0 2 47 0 2 168 65
2 30 20404 3.07 . 4.5 0 0 . . 2 47 0 2 168 65
2 30 20404 1327.4 4 . 1 1 1 12 4 47 0 2 168 65
2 30 20404 1341.57 . 4.1 0 0 . . 4 47 0 2 168 65.4
2 30 20404 1342.57 4 . 1 1 0 0 4 47 0 2 168 65.4
2 30 20404 1345.73 . 11.5 0 0 . . 4 47 0 2 168 65.4



Edit Post    Reply    Reply With Quote    Thanks       

关键词:duplicate Record R help thanks Thank record

沙发
verbatim 发表于 2011-12-3 01:44:07
Basically, in my example dataset I pasted, for first subject (ID=1), second row is his dosing record, AMT=2, DV=0,TIME=0; for second subject (ID=30), he had three dosing records, AMT=2, 4, 4 at the TIME = 0, 1327.4, 1342.57. I need duplicate these dosing records for each subject, for example, for ID=1, he will have another same dosing record besides the original one, so the goal is he will have two dosing records at TIME=0, at 2nd row and 3rd row, similar to ID=30. Thanks again.

藤椅
verbatim 发表于 2011-12-3 01:47:45
data is attached.

板凳
verbatim 发表于 2011-12-3 03:48:10
ORIGINAL DATA:
  1. C        STUD        ID        SUBJ        TIME        AMT        DV        MDV        EVID        SS        II        DOSE        AGE        NSEX        NRACE        HT        WT
  2. C        1        1        10001        -0.483        .        0        0        0                        2        21        0                180        64.5
  3.         1        1        10001        0        2        .        1        1        0        0        2        21        0                180        64.5
  4.         1        1        10001        0.6        .        0        0        0        .        .        2        21        0                180        64.5
  5.         1        1        10001        1.1        .        3.192        0        0        .        .        2        21        0                180        64.5
  6.         1        1        10001        1.52        .        6.184        0        0        .        .        2        21        0                180        64.5
  7.         1        1        10001        2.12        .        7.723        0        0        .        .        2        21        0                180        64.5
  8.         1        1        10001        2.5        .        7.59        0        0        .        .        2        21        0                180        64.5
  9.         1        1        10001        3.1        .        8.063        0        0        .        .        2        21        0                180        64.5
  10.         1        1        10001        4.1        .        8.018        0        0        .        .        2        21        0                180        64.5
  11.         1        1        10001        6.12        .        7.652        0        0        .        .        2        21        0                180        64.5
  12.         1        1        10001        12.35        .        4.616        0        0        .        .        2        21        0                180        64.5
  13.         1        1        10001        24.1        .        1.209        0        0        .        .        2        21        0                180        64.5
  14. C        1        1        10001        48        .        0        0        0                        2        21        0                180        64.5
  15. C        1        1        10001        72        .        0        0        0                        2        21        0                180        64.5
  16. C        2        30        20404        -2.6        .        .        1        0                        2        47        0        2        168        65
  17.         2        30        20404        0        2        .        1        1        0        0        2        47        0        2        168        65
  18.         2        30        20404        3.07        .        4.5        0        0        .        .        2        47        0        2        168        65
  19.         2        30        20404        1327.4        4        .        1        1        1        12        4        47        0        2        168        65
  20.         2        30        20404        1341.57        .        4.1        0        0        .        .        4        47        0        2        168        65.4
  21.         2        30        20404        1342.57        4        .        1        1        0        0        4        47        0        2        168        65.4
  22.         2        30        20404        1345.73        .        11.5        0        0        .        .        4        47        0        2        168        65.4
复制代码

报纸
verbatim 发表于 2011-12-3 03:50:48
TARGET DATASET

targetdata.xls

20 KB

TARGET DATASET

地板
zhangyangsmith 发表于 2011-12-3 07:12:45
What you need to do is just separate the dose records, merge with the original dataset before sorting it:
  1. # To read xls file
  2. library(gdata)
  3. orig <- read.xls("data.xls", perl = "perl.exe")
  4. # Separate dose records
  5. dose <- orig[orig$EVID == 1, ]
  6. # To sort data.frame
  7. library(reshape)
  8. # Merge & sort
  9. target <- sort_df(rbind(orig, dose), c("ID", "TIME"))
  10. # Output dataset as csv file
  11. # You can save it as xls in Excel, if you wish
  12. write.csv(target, file = "target.csv", quote = FALSE, na = "", row.names = FALSE)
复制代码
A few comments:
1. There may be other ways to do this task. I prefer this one because I can modify the separated dose records (change CMT, RATE, etc) for different absorption models.
2. I do not know what  is your data source. In my experience, the dose and concentration data almost always come from different sources. If I need to do the data management myself, I will keep those 2 sources of data separated right before I finish. That gives you more flexibility.
3. ASCII files are preferred than xls as it is easy to be imported into R and can be used by NM.

Glad to see another NMuser.

7
verbatim 发表于 2011-12-3 23:45:08
Thank you very much! zhangyangsmith! surprised and glad to see NMuser here! Thanks again!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 02:43