Detect matches
survivalists_small %>%
summarise(sum(str_detect(season, "1$")))
## # A tibble: 1 × 1
## `sum(str_detect(season, "1$"))`
## <int>
## 1 3
str_detect(survivalists_small$season, "1$")
## [1] FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE FALSE FALSE
sum(str_detect(survivalists_small$season, "1$"))
## [1] 3
mean(str_detect(survivalists_small$season, "1$"))
## [1] 0.3
Replacing matches
survivalists_small %>% mutate(name_rev = name %>% str_replace("^[A-Z]", "="))
## # A tibble: 10 × 4
## season name age name_rev
## <dbl> <chr> <dbl> <chr>
## 1 3 Britt Ahart 40 =ritt Ahart
## 2 8 Nate Weber 47 =ate Weber
## 3 3 Carleigh Fairchild 28 =arleigh Fairchild
## 4 1 Chris Weatherman 41 =hris Weatherman
## 5 1 Dustin Feher 37 =ustin Feher
## 6 4 Brody Wilkes 33 =rody Wilkes
## 7 2 Randy Champagne 28 =andy Champagne
## 8 1 Lucas Miller 32 =ucas Miller
## 9 9 Karie Lee Knoke 57 =arie Lee Knoke
## 10 7 Joe Nicholas 31 =oe Nicholas
survivalists_small %>% mutate(name_rev = name %>% str_replace_all("^[A-Z]", "="))
## # A tibble: 10 × 4
## season name age name_rev
## <dbl> <chr> <dbl> <chr>
## 1 3 Britt Ahart 40 =ritt Ahart
## 2 8 Nate Weber 47 =ate Weber
## 3 3 Carleigh Fairchild 28 =arleigh Fairchild
## 4 1 Chris Weatherman 41 =hris Weatherman
## 5 1 Dustin Feher 37 =ustin Feher
## 6 4 Brody Wilkes 33 =rody Wilkes
## 7 2 Randy Champagne 28 =andy Champagne
## 8 1 Lucas Miller 32 =ucas Miller
## 9 9 Karie Lee Knoke 57 =arie Lee Knoke
## 10 7 Joe Nicholas 31 =oe Nicholas
survivalists_small %>% mutate(season_rev = season %>% str_replace("1", "-"))
## # A tibble: 10 × 4
## season name age season_rev
## <dbl> <chr> <dbl> <chr>
## 1 3 Britt Ahart 40 3
## 2 8 Nate Weber 47 8
## 3 3 Carleigh Fairchild 28 3
## 4 1 Chris Weatherman 41 -
## 5 1 Dustin Feher 37 -
## 6 4 Brody Wilkes 33 4
## 7 2 Randy Champagne 28 2
## 8 1 Lucas Miller 32 -
## 9 9 Karie Lee Knoke 57 9
## 10 7 Joe Nicholas 31 7
survivalists_small %>% mutate(name_rev = name %>% str_replace_all(" ", "-"))
## # A tibble: 10 × 4
## season name age name_rev
## <dbl> <chr> <dbl> <chr>
## 1 3 Britt Ahart 40 Britt-Ahart
## 2 8 Nate Weber 47 Nate-Weber
## 3 3 Carleigh Fairchild 28 Carleigh-Fairchild
## 4 1 Chris Weatherman 41 Chris-Weatherman
## 5 1 Dustin Feher 37 Dustin-Feher
## 6 4 Brody Wilkes 33 Brody-Wilkes
## 7 2 Randy Champagne 28 Randy-Champagne
## 8 1 Lucas Miller 32 Lucas-Miller
## 9 9 Karie Lee Knoke 57 Karie-Lee-Knoke
## 10 7 Joe Nicholas 31 Joe-Nicholas
survivalists_small %>% mutate(name_rev = name %>% str_replace_all(" ", "|"))
## # A tibble: 10 × 4
## season name age name_rev
## <dbl> <chr> <dbl> <chr>
## 1 3 Britt Ahart 40 Britt|Ahart
## 2 8 Nate Weber 47 Nate|Weber
## 3 3 Carleigh Fairchild 28 Carleigh|Fairchild
## 4 1 Chris Weatherman 41 Chris|Weatherman
## 5 1 Dustin Feher 37 Dustin|Feher
## 6 4 Brody Wilkes 33 Brody|Wilkes
## 7 2 Randy Champagne 28 Randy|Champagne
## 8 1 Lucas Miller 32 Lucas|Miller
## 9 9 Karie Lee Knoke 57 Karie|Lee|Knoke
## 10 7 Joe Nicholas 31 Joe|Nicholas