str_count: counting occurences in string variable

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 | 	

I think we need more information and some sample data. Seee

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".

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.