How to I create the number column as in the table attached, which look into the Admi_num column and check if its the first admission and then put a 1 in the number column and similarly put a 2 ,3 and so on values based on the administration_num column. Thank you
Asked
Active
Viewed 102 times
0
-
1You need `data.table::rowid(PatID)` – akrun Apr 24 '21 at 17:51
-
or `dplyr::row_number()` – AnilGoyal Apr 24 '21 at 17:52
2 Answers
1
If say your data name is df
, this base R way should yield similar results
ave(df$PatID, df$PatID, FUN = function(x) seq_len(length(x)))

AnilGoyal
- 25,297
- 4
- 27
- 45