Code
# make some fake data
<- c(
id rep(1, 3),
rep(2, 2),
rep(3, 6),
rep(4, 1)
)
<- c(
ab_types 'ampicillin', 'gentamicin', 'cefalotin', 'metronidazol'
)<- sample(ab_types, size = length(id), replace = T)
ab
<- data.table::data.table(
dt id = id, ab = ab
) dt
id ab
<num> <char>
1: 1 gentamicin
2: 1 ampicillin
3: 1 cefalotin
4: 2 gentamicin
5: 2 ampicillin
6: 3 ampicillin
7: 3 cefalotin
8: 3 ampicillin
9: 3 ampicillin
10: 3 gentamicin
11: 3 cefalotin
12: 4 ampicillin