• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Oct 14th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
2.
3. #two ways to extract east and north
4. eur\$North <-str_match(eur\$GRD_ID, "1kmN(\\d\\d\\d\\d)E(\\d\\d\\d\\d)")[,2]
5. eur\$East <-str_match(eur\$GRD_ID, "1kmN(\\d\\d\\d\\d)E(\\d\\d\\d\\d)")[,3]
6. eur<-eur%>%
7. mutate(
8.     lat = as.numeric(gsub('.*N([0-9]+)[EW].*', '\\1', GRD_ID))/100,
9.     lng = as.numeric(gsub('.*[EW]([0-9]+)', '\\1', GRD_ID)) * ifelse(gsub('.*([EW]).*', '\\1', GRD_ID) == 'W', -1, 1) / 100
10.   )
12.
13. #get each countries population total
14. popu<-aggregate(eur\$TOT_P, by=list(Category=eur\$CNTR_CODE), FUN=sum)
15.
16. for (row in 1:nrow(popu)) {
17.     country <- popu[row, "Category"]
18.     TOT_P  <- popu[row, "x"]
19. }
20.
21. #now loop through each contry and find the North and east km with half the people either side
22. for (row in 1:nrow(popu)) {
23.     country <- popu[row, "Category"]
24.     TOT_P  <- popu[row, "x"]
25.
26.     Coun<-filter(eur, DATA_SRC == country)
27.
28. #stop when you have half the population
29. thresholdValue <- (TOT_P/2)
30. #head east until you have counted half the people
31. Coun<-Coun[order(Coun\$East),]
32. ix <- length(which(cumsum(Coun\$TOT_P) <= thresholdValue))
33. first<-Coun[ix,]\$East
34.
35. #head south until you have counted half the people
36. Coun<-Coun[order(Coun\$North),]
37. iy <- length(which(cumsum(Coun\$TOT_P) <= thresholdValue))
38.
39.
40. cat(country, first ,strtoi(Coun[iy,]\$North))
41.
42. cat("\n")
43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?