id: 1 1 2 2 3 3
key: ab a*b c*d*e cde a*3 3 
I simply want id as 1 2 3 and key as ab cde 3.
So basically remove each record with * in the key.
Thanks
id: 1 1 2 2 3 3
key: ab a*b c*d*e cde a*3 3 
I simply want id as 1 2 3 and key as ab cde 3.
So basically remove each record with * in the key.
Thanks
 
    
     
    
    You can use grepl to find all values of key with a *. Because * is a special character, you have to use \\ to match it. ! will negate the match.
The dplyr way
library(dplyr)
df %>% filter(!grepl('\\*', key))
#----------
  id key
1  1  ab
4  2 cde
6  3   3
Or using the full tidyverse which gives your stringr::str_detect
library(tidyverse)
df %>% filter(str_detect(key, '\\*', negate = TRUE))
Equivalents in base R
subset(df, !grepl('\\*', key))
Or
df[!grepl('\\*', df$'key'),]
# Data
df <- data.frame(id= c(1, 1, 2, 2, 3, 3),
                 key= c('ab', 'a*b', 'c*d*e', 'cde', 'a*3', 3 ))
