I have 2 dataframes. One with 4000(EPM_CODES) elements and other with 400000(df) elements.
I am trying to find out the number of occurrences of EPM_CODE
in df
. I have the following code which is working. But, taking 4 hours to complete. Is there a quicker way to accomplish this task?
Your help is appreciated.
Below is the code which I have:
for (EPM_CODE in EPM_Codes$`EPM Application Code`){
COUNT_OF_OCCURENCES <- nrow(as.data.frame(df$ELEMENT_ATTRIBUTES[grepl(paste0(",",EPM_CODE), df$ELEMENT_ATTRIBUTES) | grepl(paste0('"',EPM_CODE), df$ELEMENT_ATTRIBUTES) | grepl(paste0('_',EPM_CODE), df$ELEMENT_ATTRIBUTES) ]))
result <- cbind(EPM_CODE,COUNT_OF_OCCURENCES)
Final <- rbind(Final,result)
#print(Final)
}
Appreciate your help.