library(tidyverse)
suppressPackageStartupMessages({
library(dplyr)
library(stringr)
}
)
tibble(
name_type = c(
"apple-watch", "apple-tablet", "apple",
"apple-orange-watch", "apple-orange-tablet", "apple-orange"
)
) -> toy_data
devices <- c("watch","tablet","laptop")
toy_data %>% mutate(name_type = ifelse(str_detect(name_type,"-") == FALSE ,paste0(name_type,"-laptop"),name_type)) %>%
mutate(name_type = ifelse(str_detect(name_type,devices),name_type,paste0(name_type,"-laptop")))
#> # A tibble: 6 x 1
#> name_type
#> <chr>
#> 1 apple-watch
#> 2 apple-tablet
#> 3 apple-laptop
#> 4 apple-orange-watch
#> 5 apple-orange-tablet
#> 6 apple-orange-laptop
Created on 2020-08-06 by the reprex package (v0.3.0)