I have the following dataset,
company product_code product_number FullAddress name
1 philips p 5 Groningensingel 147,arnhem,the netherlands dhr p. jansen
2 philips p 43 Groningensingel 148,arnhem,the netherlands dhr p. hansen
3 philips x 3 Groningensingel 149,arnhem,the netherlands dhr j. Gansen
4 philips x 34 Groningensingel 150,arnhem,the netherlands dhr p. mansen
5 philips x 12 Groningensingel 151,arnhem,the netherlands dhr p. fransen
6 philips p 23 Groningensingel 152,arnhem,the netherlands dhr p. franssen
7 akzo v 43 Leeuwardenweg 178,arnhem,the netherlands dhr p. bansen
8 akzo v 12 Leeuwardenweg 179,arnhem,the netherlands dhr p. vansen
9 akzo x 5 Leeuwardenweg 180,arnhem,the netherlands dhr p. bransen
I am trying to create two new variables (product_philips and product_akzo) based on the values of 'company' variable, i.e., philips and akzo based on the below condition.
I am trying to execute the following statements,
> refine_original %>% mutate(product_philips = (if_else(grepl(pattern='philips', x=refine_original$company), 1, 0)))
> refine_original %>% mutate(product_ = (if_else(grepl(pattern='philips', x=refine_original$company), 1, 0)))
I want to instead of running twice is there any way I can run at once, I know another way using case_when function. But I want to use the same logic and functions as used above and achieve the result of having one statement instead of running multiple statements.
I want to achieve everything using dplyr package as I want to learn it more. I would be more than happy if someone could provide their viewpoints.