ds<- read.csv("https://gd.eppo.int/taxon/SIRXNO/download/distribution_csv")
str(ds)
# 'data.frame': 54 obs. of 6 variables:
# $ continent : chr "Africa" "Africa" "Africa" "Africa" ...
# $ country : chr "Algeria" "Morocco" "South Africa" "Tunisia" ...
# $ state : chr "" "" "" "" ...
# $ country.code: chr "DZ" "MA" "ZA" "TN" ...
# $ state.code : chr "" "" "" "" ...
# $ Status : chr "Present, no details" "Present, no details" "Present, no details" "Present, widespread" ...
unique(ds$country)
# [1] "Algeria" "Morocco" "South Africa"
# [4] "Tunisia" "Argentina" "Brazil"
# [7] "Canada" "Chile" "United States of America"
# [10] "Uruguay" "Mongolia" "Austria"
# [13] "Belgium" "Cyprus" "Denmark"
# [16] "Estonia" "Finland" "France"
# [19] "Georgia" "Germany" "Greece"
# [22] "Hungary" "Italy" "Norway"
# [25] "Poland" "Portugal" "Romania"
# [28] "Russia" "Serbia" "Slovenia"
# [31] "Spain" "Switzerland" "United Kingdom"
# [34] "Australia" "New Zealand"
unique(ds$state)
# [1] "" "Parana" "Rio Grande do Sul" "Santa Catarina"
# [5] "Ontario" "Connecticut" "Michigan" "New York"
# [9] "Ohio" "Pennsylvania" "Vermont" "Azores"
# [13] "Madeira" "Eastern Siberia" "Western Siberia" "Islas Canárias"
# [17] "New South Wales" "South Australia" "Tasmania" "Victoria"
I'd like to get the latlong coordinates for the state if have the state entry, if not the country coordinate. My desirable output would be something like this (not coordinates true, just to show the idea):
head(ds_coords)
continent country state country.code state.code Status lat long
1 Africa Algeria DZ Present, no details 28.0339 1.6596
2 Africa Morocco MA Present, no details 31.7917 -7.0926
3 Africa South Africa ZA Present, no details -30.5595 22.9375
4 Africa Tunisia TN Present, widespread 33.8869 9.5375
5 America Argentina AR Present, restricted distribution -38.4161 -63.6167
6 America Brazil BR Present, restricted distribution -14.2350 -51.9253