I would like to create a virtual patient data set in R , where in I would like to have the following time points TIME = seq(1, 10, 1), be repeated for 3 unique patient IDs
Asked
Active
Viewed 34 times
1 Answers
0
Thanks to the comment from @markus, you can use expand.grid
:
df <- expand.grid(TIME = 1:10, ID = 1:3)

Bjørn Kallerud
- 979
- 8
- 23
-
2I think OP is looking for `expand.grid(1:10, 1:3)` – markus Dec 09 '19 at 22:12
-
Thanks @markus I have updated my answer. – Bjørn Kallerud Dec 09 '19 at 22:16
-
thank you so much @markus and bjornkallerud – abc Dec 09 '19 at 22:28
-
how about the AMT column though ? how to add the AMT such that it appears only during the first time point for each ID? – abc Dec 09 '19 at 22:30
-
@abc Try `df$AMT <- ifelse(df$TIME == 1, 10L, NA_integer_)` – markus Dec 10 '19 at 07:48