'How can I find character being in one factor containing another factor

I would like to find each email containing each name or account, and if the character of account is included in the email, I want to get a logical value. Also, if the email changes like [email protected], I want to find out zzz. Here is the data.

account name email
zzz zzz [email protected]
zzz1 zzz1 [email protected]
zzz2 zzz2 [email protected]
zzz3 zzz3 [email protected]
zzz4 zzz4 [email protected]
zzz5 zzz5 [email protected]
zzz6 zzz6 [email protected]
zzz7 zzz7 [email protected]
zzz8 zzz8 [email protected]
zzz9 zzz9 [email protected]

I tried two ways seperately, but I got an error.

ifelse(df$email %in% df$account, "1", "0")
str_detect(df$email,df$account)

Then, how can I know that each row of account is contained in each row of email.

r


Solution 1:[1]

I solved a problem with as.character()

str_detect(as.character(df$email),as.character(df$account))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edison Thomas