First post, I'll try to do my best.
I'm trying to make an interactive choropleth map with leaflet in R, based off this tutorial. It all goes great until I compare the data represented on the map with the data in my data frame.
I'm using the same data as the person who wrote the tutorial. It is a Large Spatial Polygons Dataframe called world_spdf with 246 rows of world_spdf@data and world_spdf@polygons as well as three other objects I have no idea about. The data is essentially countries with long and lat. I don't know anything about spatial data, but I'm assuming it's responsible for the shapes of the countries on a rendered map.
I also have a data frame called results that initially has 234 rows, also about countries and some additional data for each country. This is how head(results) looks like (it goes on like this, and there are no NAs):
ISO2 v1 v2 v3
<chr> <dbl> <dbl> <dbl>
1 AD 0.118 0.880 0.001
2 AE 0.226 0.772 0.0016
3 AF 0.197 0.803 0.0001
4 AG 0.0884 0.911 0.0009
5 AI 0.172 0.827 0.00120
6 AL 0.107 0.891 0.0022
I am merging the two dataframes by ISO2 column which contains country codes. Everything is fine so far, the data in the merged dataframe is correctly assigned to the country.
world_spdf@data = merge(world_spdf@data, results, by = "ISO2")
However, when I try to plot the data, the resulting interactive map presents the data in a "wrong order", for example, data for Poland for Nigeria etc.
What I tried was to find the missing countries in the smaller dataframe like this:
differences = c(setdiff(world_spdf@data$ISO2, results$ISO2)
And then add rows with NAs to the dataframe so that all the countries in the spatial dataframe are represented with NAs at least. But this didn't help.
I am clueless as to why this occurs. Please help!

results. So I cannot help you. But I have the impression that the merge process screwed up something. If you can provide theresultsobject and your code, someone will be able to help you out here. - jazzurro