- , :
indx <- (grepl('Bill Payment', df1$Product) & grepl('Mobile', df1$Product)) +
(grepl('Recharge', df1$Product) & grepl('Mobile', df1$Product))*2 + 1L
df1$category <- c(NA, "Postpaid", "Prepaid")[indx]
:
> df1
Product category
1 Bill Payment for Torrent Power Limited <NA>
2 Recharge of Videocon d2h DTH <NA>
3 Bill Payment of Airtel Mobile Postpaid
4 Recharge of Idea Mobile Prepaid
, , @akrun:
indx <- grepl('.*Bill Payment.*Mobile.*', df1$Product) +
grepl('.*Recharge.*Mobile.*', df1$Product)*2 + 1L
@nicola :
tmp <- grepl('Mobile', df1$Product)
indx <- (grepl('Bill Payment', df1$Product) & tmp) + (grepl('Recharge', df1$Product) & tmp)*2 + 1L