79306581

Date: 2024-12-24 22:35:37
Score: 0.5
Natty:
Report link

Here is one way to accomplish your goal using str_like function form stringr

df <- tibble(x = c("id1","id2", "id3", "id4"),
             y  = c("data", "data_analyst", "test", "test_analyst"))

df2 <- tibble(z = c("data1", "data", "test1", "test")) %>% 
  arrange(z)

merged <- cbind(df,df2)

merged %>% 
  mutate(pattrn_match = ifelse(str_like(y, "data"),  "pattern matching (data)", 
                               ifelse(str_like(y, "test"), "pattern matching (test)", "pattern not matching" )))

### final output 
x
<chr>
y
<chr>
z
<chr>
pattrn_match
<chr>
id1 data    data    pattern matching (data) 
id2 data_analyst    data1   pattern not matching    
id3 test    test    pattern matching (test) 
id4 test_analyst    test1   pattern not matching    
4 rows
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user28876813