AKA how start getting around using grep, grepl, sub, gsub, regexp, gregexp.
Main difference between them is that while
grepl matches to
pattern within the character vector,
gregexpr return more detail.
gsub perform replacement on the basis of a regular expression.
This is my version of lazy labeling: run the same code changing just the input dataset
file <- "BEN_Benin_2013" #myfile
clabel <- substring(file, 1, 3) #country label is the iso3 code
cname <-sub( ".*_(.*)_.*", "\\1", file) #country name
year <- sub( ".*_(.*)_*", "\\1", file) #census year
More to follow on grep and grepl…