1. Dado el vector de emails:
emails <- c("john.doe@ivyleague.edu", "education@world.gov", "dalai.lama@peace.org",
            "invalid.edu", "quant@bigdatacollege.edu", "cookie.monster@sesame.tv")
grepl(---)
grepl(pattern = "edu", x=emails)
## [1]  TRUE  TRUE FALSE  TRUE  TRUE FALSE
hits <- ---
hits <- grep(pattern = "edu", x=emails)
emails[hits]
## [1] "john.doe@ivyleague.edu"   "education@world.gov"     
## [3] "invalid.edu"              "quant@bigdatacollege.edu"
  1. Dado el vector de emails:
emails <- c("john.doe@ivyleague.edu", "education@world.gov", "dalai.lama@peace.org",
            "invalid.edu", "quant@bigdatacollege.edu", "cookie.monster@sesame.tv")
grepl(---)
grepl(pattern = "@.*\\.edu$", x=emails)
## [1]  TRUE FALSE FALSE FALSE  TRUE FALSE
hits <- ---
hits <- grep(pattern = "@.*\\.edu$", x=emails)
emails[hits]
## [1] "john.doe@ivyleague.edu"   "quant@bigdatacollege.edu"
  1. Dado el vector de emails:
emails <- c("john.doe@ivyleague.edu", "education@world.gov", "dalai.lama@peace.org",
            "invalid.edu", "quant@bigdatacollege.edu", "cookie.monster@sesame.tv")

Usa sub() para sustituir los dominios de los email que acaban en .edu por “midominio.edu”

sub()
sub(pattern = "@.*\\.edu$", replacement = "@midominio.edu", x=emails)
## [1] "john.doe@midominio.edu"   "education@world.gov"     
## [3] "dalai.lama@peace.org"     "invalid.edu"             
## [5] "quant@midominio.edu"      "cookie.monster@sesame.tv"
  1. Dado el vector:
cities <- c("new york", "los angeles", "san francisco")

Escribe el código para obtener la salida:

## [1] "nuw york"      "los ungeles"   "sun francisco"
sub(---)
sub(pattern = "e|a", replacement = "u", x = cities)
## [1] "nuw york"      "los ungeles"   "sun francisco"
  1. Dado el vector:
animals <- c("cat", "moose", "impala", "ant", "kiwi")

Escribe el código para obtener la salida:

## [1] "cat"    "maasa"  "ampala" "ant"    "kawa"
gsub(---)
gsub(pattern = "o|i|e", replacement = "a", x = animals)
## [1] "cat"    "maasa"  "ampala" "ant"    "kawa"