Trying to count occurrences of various medications in an open response variable- using the below, and some are not being counted-
df_linelist$malaria_meds_prescribed <- str_count(tolower(df_linelist$medication_prescribed2),"ALU Adult | Amodiaquine | Anti-Malaria | Anti-Malaria drugs | Anti-Malaria injection | Artemether and Lumefantrin (Coartem) | Artesunate +Lumfrantrime | Artesunate | Artesunate Injection | Artesunate injection | chloroquine | chloroquine sirop | Coartem | Coartem (Artemether and Lumefantrin) | I.V Artesunate/ Artesunate injections | Plaquenil | Quinine tabs |
chloroquine,")
I think we need more information and some sample data. Seee
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
Without seeing some sample data, I can only take a guess. The function str_count(input, "Regex pattern") uses Regex which means your input has to match exactly the Regex string. 1) You could try changing the prescriptions in the Regex string to be all lowercase. and 2) Check the spaces surrounding " | "... For example, "alu adult | amodiaquine | anti-malaria " does not equal "alu adult|amodiaquine|anti-malaria".
system
Closed
May 17, 2021, 7:15pm
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.