I have a dataframe containing text in a cell. The length of the text is not fixed. Now I want to extract 2 words and want to store them in 2 columns.
The 2 words starting with DB and then containing 5 numbers. Like, DB00001 and DB01569.
The full text like this,
DB00614 may increase the anticholinergic activities of DB06153.
The risk or severity of adverse effects can be increased when DB00802 is combined with DB00310.
I am using this code and working fine. But, I think , the code can be more optimized.
test_df <- deepDDI %>% mutate(
parent_key = str_extract_all(deepDDI$des, "(DB)(\\d+)")
) %>%
select(parent_key) %>%
separate(parent_key, into=c("nodeA", "nodeB"), sep=",")
test_df[] <- lapply(test_df, gsub, pattern = '"', replacement= '')
test_df[] <- lapply(test_df, gsub, pattern = ')', replacement= '')
test_df[] <- lapply(test_df, gsub, pattern = '\\(', replacement= '')
test_df[] <- lapply(test_df, gsub, pattern = 'c', replacement= '')
How can I optimize the code?