I've got a dataset of ICD codes, 5 digit codes which describe the diagnosis of a hospital patients, which looks like this (but with 16000 patients):
df <- c('S48.10', 'H38.13', 'R40.12')
I need to filter them based on the first character being an S and the third character being an 8 to filter out amputation patients. Any advice on how to do this?
Here is an option with
grepl
on the ICD column. The pattern used is 'S' followed by any character (.
) followed by 8 from the start (^
) of the string to filter the rows of the datasest