Fàîžà!
My solution involves creating a new column in your dataframe which indicates TRUE if the surname and nickname are exactly the same and FALSE if they are not exactly the same.
To do this, you need the dplyr package:
surname <- c("Smith", "Potter", "Smith")
nickname <- c("Bobby", "Potter", "Smith")
df <- data.frame(surname = x, nickname = y)
Now that we have the dataframe, let's add the dplyr code:
library(dplyr)
df <- df %>%
mutate(equal_names = case_when(
surname == nickname ~ TRUE,
surname != nickname ~ FALSE))
The result is:
> df
surname nickname equal_names
1 Smith Bobby FALSE
2 Potter Potter TRUE
3 Smith Smith TRUE
case_when()
returns whatever you want after the specified condition.
If you want more advanced screening, you'd need to check how regular expressions work. This post has a few hints about this.