respeciate_generic {epidm} | R Documentation |
Respeciate unspecified samples
Description
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.
Usage
respeciate_generic(
x,
group_vars,
species_col,
date_col,
window = c(0:Inf),
.forceCopy = FALSE
)
Arguments
x |
a data.frame or data.table object |
group_vars |
the minimum grouping set of variables for like samples in a character vector; suggest c('patient_id','specimen_type','genus') |
species_col |
a character containing the column with the organism species_col name |
date_col |
a character containing the column with the specimen/sample date_col |
window |
an integer representing the number of days for which you will allow a sample to be respeciated |
.forceCopy |
default FALSE; TRUE will force data.table to take a copy instead of editing the data without reference |
Value
a data.table with a recharacterised species_col
column
Examples
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)[]