mardi 3 mars 2020

Unable to use a lookup function as one of the values in an ifelse statement In R

I am currently trying to add another column to my data frame in R. I am trying to dictate the values of the column based by using an ifelse statement where logic is using grepl to detect based on a string. True statements should have an output of a string and the false should lookup the value from another dataframe. The issue is that the output of the false values is indexed numbers rather than the actual string looked up from the other data frame.

here is the code and output when aggregated by count

joined = joined %>% mutate(RM = ifelse(grepl("Churn",joined$campaign_name), "churn",lookup(joined$campaign_name, rm_type, missing = NA)))

   1      2      3      4      5  Churn 
280464    252     83   2858    339    731 

The rm data frame is a dataframe with campaign names and their corresponding type which transforms to numbers in the ifelse function.

Thank you!

Aucun commentaire:

Enregistrer un commentaire