Reputation: 21
Sorry if this isn't laid out correctly, still in very early stages of R and these forums!
I have an extremely large, global dataset split into countries using the ISO country code however I am only after the European countries.
I can successfully highlight one variable from the dataset
test1[country_code=="BE",]
How can I extract all the European codes? I have tried & and | but unsuccessfully.
Upvotes: 1
Views: 92
Reputation: 86
This creates a new data table (single column) with the list of all unique country codes :
country.codes <- as.data.table(unique(test1[,country_code]))
You can easily determine the European country codes from the newly extracted small list of country codes.
Upvotes: 1
Reputation: 408
try defining a list of Euro countries, then make use of %in%
euro_codes <- c('BE', 'DE', ...)
test1[ country_code %in% euro_codes, ]
Upvotes: 5