View source: R/bt_guess_country.R
bt_guess_country | R Documentation |
Not perfect - biased towards more common countries, e.g. may return 'United Kingdom' when string contains 'British Columbia' etc. Set param top.match.only = F to return all guesses The results are in alphabetical order, not the order they appear in the string.
bt_guess_country(tgt.string, placeholder.result = NA, top.match.only = T)
tgt.string |
vector of string containing country name(s) |
placeholder.result |
what to return instead of NA when guess fails |
top.match.only |
whether you want the first match, or a vector of matches |
This function should work on strings or char vectors.
vector of the GTA names of all matches in alphabetical order.
www.globaltradealert.org
tgt.string.vect = c("In Britain, postman delivers fancy dress joy to isolating residents", "UK man turns out to be an idiot", "Something afoot in Japan")
for(tgt.string in tgt.string.vect){
print(bt_guess_country(tgt.string))
}
Usage example:
for (i in 1:nrow(update.table)){
guessed.country = bt_guess_country(update.table$art.description.en[i])
if(length(guessed.country)){
update.table$art.country[i] = guessed.country
} else {
update.table$art.country[i] = "Unknown"
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.