Some samples within SGSS are submitted by laboratories as "GENUS SP" or "GENUS UNNAMED". However, they may also have a fully identified sample taken from the same site within a recent time period. This function captures species_col from another sample within X-days of an unspeciated isolate.
respeciate_generic(
x,
group_vars,
species_col,
date_col,
window = c(0:Inf),
.forceCopy = FALSE
)
a data.frame or data.table object
the minimum grouping set of variables for like samples in a character vector; suggest c('patient_id','specimen_type','genus')
a character containing the column with the organism species_col name
a character containing the column with the specimen/sample date_col
an integer representing the number of days for which you will allow a sample to be respeciated
default FALSE; TRUE will force data.table to take a copy instead of editing the data without reference
a data.table with a recharacterised species_col
column
df <- data.frame(
ptid = c(round(runif(25,1,5))),
spec = sample(c("KLEBSIELLA SP",
"KLEBSIELLA UNNAMED",
"KLEBSIELLA PNEUMONIAE",
"KLEBEIELLA OXYTOCA"),
25,replace = TRUE),
type = "BLOOD",
specdate = sample(seq.Date(Sys.Date()-21,Sys.Date(),"day"),25,replace = TRUE)
)
respeciate_generic(x=df,
group_vars=c('ptid','type'),
species_col='spec',
date_col='specdate',
window = 14)[]
#> 14-day round 1: 9 SP or UNNAMMED isolates respeciated
#> 14-day round 2: 0 SP or UNNAMMED isolates respeciated
#> ptid spec type specdate
#> 1: 1 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-27
#> 2: 1 KLEBEIELLA OXYTOCA BLOOD 2022-07-03
#> 3: 1 KLEBSIELLA PNEUMONIAE BLOOD 2022-07-08
#> 4: 2 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-22
#> 5: 2 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-23
#> 6: 2 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-23
#> 7: 2 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-26
#> 8: 2 KLEBEIELLA OXYTOCA BLOOD 2022-06-27
#> 9: 2 KLEBEIELLA OXYTOCA BLOOD 2022-07-01
#> 10: 2 KLEBEIELLA OXYTOCA BLOOD 2022-07-05
#> 11: 2 KLEBEIELLA OXYTOCA BLOOD 2022-07-06
#> 12: 2 KLEBEIELLA OXYTOCA BLOOD 2022-07-08
#> 13: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-20
#> 14: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-21
#> 15: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-27
#> 16: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-27
#> 17: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-28
#> 18: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-07-04
#> 19: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-07-07
#> 20: 3 KLEBSIELLA PNEUMONIAE BLOOD 2022-07-09
#> 21: 4 KLEBSIELLA PNEUMONIAE BLOOD 2022-06-20
#> 22: 4 KLEBEIELLA OXYTOCA BLOOD 2022-06-21
#> 23: 4 KLEBEIELLA OXYTOCA BLOOD 2022-06-28
#> 24: 4 KLEBEIELLA OXYTOCA BLOOD 2022-07-08
#> 25: 5 KLEBSIELLA PNEUMONIAE BLOOD 2022-07-06
#> ptid spec type specdate