Import your data

results <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-07/results.csv')
## Warning: One or more parsing issues, see `problems()` for details
## Rows: 25220 Columns: 18
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (8): position, positionText, time, milliseconds, fastestLap, rank, fast...
## dbl (10): resultId, raceId, driverId, constructorId, number, grid, positionO...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
set.seed(1234)
results_small <- results %>% sample_n(10)
results_small
## # A tibble: 10 × 18
##    resultId raceId driverId constr…¹ number  grid posit…² posit…³ posit…⁴ points
##       <dbl>  <dbl>    <dbl>    <dbl>  <dbl> <dbl> <chr>   <chr>     <dbl>  <dbl>
##  1     7452    333      110       35     22    18 "\\N"   R            25      0
##  2     8016    359      127       37     15     0 "\\N"   F            28      0
##  3     7162    325      138       25      3    13 "11"    11           11      0
##  4     8086    361      158       21     10    16 "\\N"   R            20      0
##  5    23657    982      826        5     26    13 "\\N"   R            16      0
##  6     9196    396      102       32     12     6 "2"     2             2      6
##  7      623     47       18       11      7    21 "13"    13           13      0
##  8    15241    617      309        1      8     2 "3"     3             3      4
##  9    10885    460      182        1      8    15 "6"     6             6      1
## 10      934     61       35        2     17    11 "\\N"   R            16      0
## # … with 8 more variables: laps <dbl>, time <chr>, milliseconds <chr>,
## #   fastestLap <chr>, rank <chr>, fastestLapTime <chr>, fastestLapSpeed <chr>,
## #   statusId <dbl>, and abbreviated variable names ¹​constructorId, ²​position,
## #   ³​positionText, ⁴​positionOrder

Chapter 14

Tools

Detect matches

results_small %>%
    filter(str_detect(points, "6"))
## # A tibble: 1 × 18
##   resultId raceId driverId constru…¹ number  grid posit…² posit…³ posit…⁴ points
##      <dbl>  <dbl>    <dbl>     <dbl>  <dbl> <dbl> <chr>   <chr>     <dbl>  <dbl>
## 1     9196    396      102        32     12     6 2       2             2      6
## # … with 8 more variables: laps <dbl>, time <chr>, milliseconds <chr>,
## #   fastestLap <chr>, rank <chr>, fastestLapTime <chr>, fastestLapSpeed <chr>,
## #   statusId <dbl>, and abbreviated variable names ¹​constructorId, ²​position,
## #   ³​positionText, ⁴​positionOrder

Extract matches

results_small %>% 
    mutate(points_ext = str_extract(points, "0")) %>%
    select(points, points_ext)
## # A tibble: 10 × 2
##    points points_ext
##     <dbl> <chr>     
##  1      0 0         
##  2      0 0         
##  3      0 0         
##  4      0 0         
##  5      0 0         
##  6      6 <NA>      
##  7      0 0         
##  8      4 <NA>      
##  9      1 <NA>      
## 10      0 0

Replacing matches

results_small %>%
    mutate(points = str_replace(points, "0", "none")) %>%
    select(points)
## # A tibble: 10 × 1
##    points
##    <chr> 
##  1 none  
##  2 none  
##  3 none  
##  4 none  
##  5 none  
##  6 6     
##  7 none  
##  8 4     
##  9 1     
## 10 none