Using R (in RStudio). I need to a new flag column indicating the presence of a medicine component named in one column of my data frame where that component may stand alone or be one of several components. The new column needs to be in the dataframe because it will be used as a look up table (it has a unique key variable in one column) in a relational database. How can I use Str_extract and mutate to accomplish this (or should I take another approach)?
I have a data frame of 14 columns and 400K plus rows. The rows are individual specific pharmaceutical products, the columns describe their components. One column contains the generic names of medicines. Most rows in this column have a single drug name, some have multiple drug components, written for example as acetaminophen/pseudoephedrine/ibuprofen. I am interested in about 50 specific generic drugs among the hundreds of different medicine names. For example ibuprofen. I will need to a column that flags whether a specific drug is contained in the generic names, i.e. has a value of TRUE or FALSE. I need to add this to the data frame because other columns contain other characteristics including a key for matching the drug in another relational database. My thought is to use str_detect (in stringr) to match Ibuprofen in the drug name column and give the value TRUE or FALSE in the new column "Contains_Ibuprofen" created using mutate (tidyr, dplyr). How can I can I use Str_extract and mutate to accomplish this (or should I take another approach)?
I dont know how to use str_detect on a data frame with mutate to create a new column. Or should I use a different approach?