Funkce extract z tidyr

Intermediate Regular Expressions in R

Angelo Zehr

Data Journalist

Dosud použité funkce

  • str_match
  • str_replace
  • str_match_all
  • str_replace_all
  • ...
Intermediate Regular Expressions in R

Kde se setkávají regulární výrazy a datové rámce:

extract(
    data,
    col,
    into,
    regex = "([[:alnum:]]+)",
    remove = TRUE,
    convert = FALSE,
    ...
 )
Intermediate Regular Expressions in R

Argumenty funkce extract

extract(
    data,
    col,
    into,
    regex = "([[:alnum:]]+)",
    remove = TRUE,
    convert = FALSE,
    ...
 )
  • data

  • col

  • into

  • regex

  • remove

  • convert

Intermediate Regular Expressions in R

Datový rámec filmů

Intermediate Regular Expressions in R

Co lze dělat s str_match

snímek tabulky

screens_per_movie %<>%
  mutate(
    is_3d = str_match(line, "3D")
  )
Intermediate Regular Expressions in R

Výsledek funkce str_match

snímek tabulky

screens_per_movie %<>%
  mutate(
    is_3d = str_match(line, "3D")
  )
Intermediate Regular Expressions in R

str_match dokáže zachytit pouze jednu informaci

snímek tabulky

Intermediate Regular Expressions in R

Co pro nás dokáže extract

Intermediate Regular Expressions in R

Co pro nás dokáže extract

snímek tabulky

extract(
  screens_per_movie,
  col = "line",
  into = c("is_3d", "screens"),
  regex = "(3D).*?(\\d+)$",
  remove = FALSE
 )
Intermediate Regular Expressions in R

Výsledek funkce extract

snímek tabulky

extract(
  screens_per_movie,
  col = "line",
  into = c("is_3d", "screens"),
  regex = "(3D).*?(\\d+)$",
  remove = FALSE
)
Intermediate Regular Expressions in R

Pojďme si procvičit!

Intermediate Regular Expressions in R

Preparing Video For Download...