How to use R

Foundational notions of R language

  1. Vectors
Vectors

Vectors

  - Numeric
  - Logical / Boolean
  - Character

“object-oriented programming language”

apple <- c(2020123456, 20197890123, 2020456789, 201812345)
sale <- c("apple", "banana", "kiwi", "melon")
sale
## [1] "apple"  "banana" "kiwi"   "melon"
sales <- c(sale, apple)
sales
## [1] "apple"       "banana"      "kiwi"        "melon"       "2020123456" 
## [6] "20197890123" "2020456789"  "201812345"
length(apple)
## [1] 4
length(sales)
## [1] 8
  1. Lists

    Containers of objects

my_list <- list(apple, sales)

class(my_list)
## [1] "list"
  - Creating lists
  - Subsetting lists
  1. Data frames

    • All components are vectors, no matter whether logical, numerical, or character
    • All vectors must be of the same length
library(tibble)
tibble(school_id=apple, favorite_fruit=sale)
## # A tibble: 4 x 2
##     school_id favorite_fruit
##         <dbl> <chr>         
## 1  2020123456 apple         
## 2 20197890123 banana        
## 3  2020456789 kiwi          
## 4   201812345 melon
Data frames

Data frames

  1. Packages
#install.packages("tidyverse")
library(tidyverse)
  - Select and show a column of a data frame
  - Add a new column
  1. Functions
Function

Function

  - Ways of manipulating vectors, lists, and data frames
adding_two <- function(x){
  x+2
}

adding_two(x=3)
## [1] 5
my_func <- function(x){
  function_result <- x / 2
}

my_func <- function(x){
  function_result <- x / 2
  return(function_result)
}
a <- 2

my_func <- function(x){
  function_result <- x / 2 + a
  return(function_result)
}

my_func(20) + a 
## [1] 14

R에서 프로젝트 사용하기

RStudio 프로젝트를 사용하면 작업 결과와 데이터를 쉽게 관리 할 수 있습니다.

프로젝트 만들기

RStudio 프로젝트는 R 작업 디렉토리와 연결됩니다. RStudio 프로젝트를 다음과 같은 곳에 만들 수 있습니다.

  • 새로운 디렉토리에서
  • 또는 이미 R 코드 및 데이터가 있는 기존 디렉토리에서 만들 수 있습니다.

새로운 프로젝트를 만들 때, R studio는 :

  1. 프로젝트 디렉토리에 (.Rproj 확장자를 가진) 프로젝트 파일을 생성합니다. 이 파일에는 다양한 프로젝트 옵션이 있고 프로젝트를 직접 여는 지름길로 파일을 사용합니다.
  2. 원본 문서와 창 상태가 저장된 숨겨진 디렉토리를 만듭니다.
  3. 프로젝트를 저장하고 툴바에 프로젝트 이름을 나타냅니다.

프로젝트 열기

  1. Open Project 명령어를 사용하여 기존 프로젝트 파일(예: R.Rproj)을 찾아 선택합니다.
  2. 또는 최근 열었던 프로젝트 목록에서 프로젝트를 선택합니다.

프로젝트 종료하기

프로젝트를 종료하거나 다른 프로젝트를 열면 다음 작업이 실행됩니다. :

  • .RData 및/또는 .Rhistory 는 프로젝트 디렉토리에 기록됩니다.
  • 오픈 소스 문서(.R 확장 문서) 목록이 저장됩니다. (다음 번에 프로젝트를 열 때, 복원할 수 있습니다.)

Global 옵션 확인

작업 내용이 올바르게 저장되도록 global 옵션을 확인해 봅시다.

  • Restore .RData into workspace at startup - 시작 시, R 작업 공간(전역 환경) 안에 초기 작업 디렉토리에 있는 .RData 파일(있는 경우)을 저장하세요.
  • Save workspace to .RData on exit - 종료 시, .RData를 저장할지 여부를 묻고 항상 저장하거나 저장하지 않습니다.
  • Always save history (even when not saving .RData) - 종료할 때, .RData 파일을 저장하지 않기로 선택하더라도 세션의 명령을 사용하여 .Rhistory 파일이 항상 저장되는지 확인하세요.

R 패키지

R을 사용하여 웹스크래핑을 할 경우 관련 패키지를 설치하면 데이터 긁어오기, 전처리와 분석은 물론 결과의 시각화 작업을 보다 편리하고 효율적으로 수행할 수 있다.

패키지? 라이브러리?

R은 오픈 소스 소프트웨어로서 웹 스크래핑&크롤링에 특화되어있는 기능들을 잘 활용하는 것이 중요하다.

패키지는 R의 함수들이 목적에 따라 모여있는 집합체를 말한다.

라이브러리는 패키지를 다운로드 받은 장소를 말한다. 저장된 패키지를 R에 설치함으로서 우리는 포함되어 있는 함수들을 활용할 수 있게 된다. 그렇다면, R에서 어떻게 패키지를 다운로드 받고 설치할 수 있을까?

가령, 우리가 데이터를 수집, 분석하기 위해 필요한 함수들이 “stringr”, “RCurl”, “XML”, 그리고 “maps” 라는 패키지에 포함되어 있다고 가정해보자. 패키지들을 다운로드 받기위해서는 다음의 코드를 실행해야 한다.

install.packages("stringr")

install.packages("RCurl")

install.packages("XML")

install.packages("maps")

특히, install.packages라는 함수 뒤에 괄호가 따라오게 되는데, 이 괄호 안에 패키지의 이름이 입력된다. 주의점: 패키지의 이름은 문자 코드이기 때문에 따옴표를 붙여줘야 한다.

위의 정보를 입력하면 R은 해당 패키지를 CRAN이라는 서버로부터 다운로드 받는다. 하지만 패키지를 다운로드 받았을 뿐, 해당 함수를 실행하기 위해서 패키지를 R 세션에 “로드”해야하는 과정이 필요하다. 이 작업은 library()라는 함수로 실행한다.

library(stringr)
library(RCurl)
## 
## Attaching package: 'RCurl'
## The following object is masked from 'package:tidyr':
## 
##     complete
library(httr)
library(XML)
library(maps)
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map

이러한 과정을 거치게 되면 우리는 오늘 R에서의 웹 스크래핑과 분석 결과의 시각화를 위한 패키지 설치를 완료하게 된다.

작업 디렉토리란?

텍스트를 분석하기 위해 다운로드 받은 디지털 문서가 저장되어 있는 장소를 알아야 R로 파일을 불러올 수 있다. 이때 필요한 정보가 Working Directory이다. 이 폴더는 R session에서 작업하는 파일들의 주소로서 다음의 함수를 이용하면 알 수 있다.

getwd() # 현재 작업중인 디렉토리 찾기 (입력 및 출력값이 저장되는 장소)
## [1] "C:/Users/CAU/Dropbox/2020_Class/fall/big data methodology/R"

Case study: World Heritage Sites in Danger

  1. Generate some research questions

    • 1,121 heretage sites like the Pyramids in Egypt

    • Which sites are threatened and where are they located?

    • Are there regions in the world where sitets are more endangered than in others?

    • What are the reasons that put a site at risk?

    Questions to be considered in data collection

    1. What type of data is most suited to answer your question?

    2. Is the quality of the data sufficiently high to answer your question?

    3. Is the information systematically flowed (biased)?

  2. Find a source of data that can be used to answer the questions

https://en.wikipedia.org/wiki/List_of_World_Heritage_in_Danger

  1. Import content from a web page into R
#heritage_page <- getURLContent("https://en.wikipedia.org/wiki/List_of_World_Heritage_in_Danger")
#class(heritage_page)

library(httr)

heritage_page <- GET("https://en.wikipedia.org/wiki/List_of_World_Heritage_in_Danger")
heritage_page
## Response [https://en.wikipedia.org/wiki/List_of_World_Heritage_in_Danger]
##   Date: 2020-09-16 05:19
##   Status: 200
##   Content-Type: text/html; charset=UTF-8
##   Size: 496 kB
## <!DOCTYPE html>
## <html class="client-nojs" lang="en" dir="ltr">
## <head>
## <meta charset="UTF-8"/>
## <title>List of World Heritage in Danger - Wikipedia</title>
## <script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames...
## "Featured lists","Lists of World Heritage Sites","World Heritage Sites in Dan...
## "ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","...
## "ext.uls.interface","ext.cx.eventlogging.campaigns","ext.quicksurveys.init","...
## <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.implement("user.option...
## ...
class(heritage_page)
## [1] "response"
  1. Parse the content in the form of an HTML document and extract HTML tables
heritage_parsed <- htmlParse(heritage_page, encoding = "UTF-8")
class(heritage_parsed)
## [1] "HTMLInternalDocument" "HTMLInternalDocument" "XMLInternalDocument" 
## [4] "XMLAbstractDocument"
tables <- readHTMLTable(heritage_parsed, stringsAsFactors = FALSE)
class(tables)
## [1] "list"
length(tables)
## [1] 5
tables[[2]][1:10,]
##                                     V1    V2
## 1                                 Name Image
## 2                             Abu Mena      
## 3      Air and Tenere Natural Reserves      
## 4               Ancient City of Aleppo      
## 5                Ancient City of Bosra      
## 6             Ancient City of Damascus      
## 7   Ancient Villages of Northern Syria      
## 8        Archaeological Site of Cyrene      
## 9  Archaeological Site of Leptis Magna      
## 10     Archaeological Site of Sabratha      
##                                                                                                                                                                          V3
## 1                                                                                                                                                                  Location
## 2                              EgyAbusir,<U+00A0>Egypt30°50′30″N 29°39′50″E<U+FEFF> / <U+FEFF>30.84167°N 29.66389°E<U+FEFF> / 30.84167; 29.66389<U+FEFF> (Abu Mena)
## 3              Niger1Arlit Department,<U+00A0>Niger18°17′N 8°0′E<U+FEFF> / <U+FEFF>18.283°N 8.000°E<U+FEFF> / 18.283; 8.000<U+FEFF> (Air and Tenere Natural Reserves)
## 4                      Aleppo Governorate, <U+00A0>Syria36°14′N 37°10′E<U+FEFF> / <U+FEFF>36.233°N 37.167°E<U+FEFF> / 36.233; 37.167<U+FEFF> (Ancient City of Aleppo)
## 5         Daraa Governorate, <U+00A0>Syria32°31′5″N 36°28′54″E<U+FEFF> / <U+FEFF>32.51806°N 36.48167°E<U+FEFF> / 32.51806; 36.48167<U+FEFF> (Ancient City of Bosra)
## 6  Damascus Governorate, <U+00A0>Syria33°30′41″N 36°18′23″E<U+FEFF> / <U+FEFF>33.51139°N 36.30639°E<U+FEFF> / 33.51139; 36.30639<U+FEFF> (Ancient City of Damascus)
## 7                       Syria36°20′3″N 36°50′39″E<U+FEFF> / <U+FEFF>36.33417°N 36.84417°E<U+FEFF> / 36.33417; 36.84417<U+FEFF> (Ancient Villages of Northern Syria)
## 8   LibJebel Akhdar,<U+00A0>Libya32°49′30″N 21°51′30″E<U+FEFF> / <U+FEFF>32.82500°N 21.85833°E<U+FEFF> / 32.82500; 21.85833<U+FEFF> (Archaeological Site of Cyrene)
## 9    LibKhoms,<U+00A0>Libya32°38′18″N 14°17′35″E<U+FEFF> / <U+FEFF>32.63833°N 14.29306°E<U+FEFF> / 32.63833; 14.29306<U+FEFF> (Archaeological Site of Leptis Magna)
## 10     LibSabratha,<U+00A0>Libya32°48′19″N 12°29′6″E<U+FEFF> / <U+FEFF>32.80528°N 12.48500°E<U+FEFF> / 32.80528; 12.48500<U+FEFF> (Archaeological Site of Sabratha)
##                               V4                     V5         V6           V7
## 1                       Criteria          Areaha (acre) Year (WHS)   Endangered
## 2                  Cultural:(iv)              182 (450)       1979 2001<U+2013>
## 3       Natural:(vii), (ix), (x) 7,736,000 (19,120,000)       1991 1992<U+2013>
## 4             Cultural:(iii)(iv)              350 (860)       1986 2013<U+2013>
## 5          Cultural:(i)(iii)(vi)               <U+2014>       1980 2013<U+2013>
## 6  Cultural:(i)(ii)(iii)(iv)(vi)               86 (210)       1979 2013<U+2013>
## 7          Cultural:(iii)(iv)(v)        12,290 (30,400)       2011 2013<U+2013>
## 8     Cultural:(ii), (iii), (vi)               <U+2014>       1982 2016<U+2013>
## 9      Cultural:(i), (ii), (iii)               <U+2014>       1982 2016<U+2013>
## 10                Cultural:(iii)               <U+2014>       1982 2016<U+2013>
##                                                                                                                                             V8
## 1                                                                                                                                       Reason
## 2                               Cave-ins in the area caused by the clay at the surface, which becomes semi-liquid when met with "excess water"
## 3  Military conflict and civil disturbance in the region as well as a reduction of wildlife population and degradation of the vegetation cover
## 4                                                  Syrian Civil War, currently held by the government. Bombings continue threatening the site.
## 5                                                                                                    Syrian Civil War, held by the government.
## 6                                Syrian Civil War, rebel gunfire and mortar shelling, mainly from adjacent Jobar suburb endangers foundations.
## 7                                                Syrian Civil War, some held by rebels. Reports of looting and demolitions by Islamist groups.
## 8                                                   Libyan Civil War, presence of armed groups, already incurred and potential further damage.
## 9                                                   Libyan Civil War, presence of armed groups, already incurred and potential further damage.
## 10                                                  Libyan Civil War, presence of armed groups, already incurred and potential further damage.
##              V9
## 1          Refs
## 2  [17][18][19]
## 3      [20][21]
## 4          [22]
## 5          [23]
## 6          [24]
## 7          [25]
## 8      [26][27]
## 9      [27][28]
## 10     [27][29]
  1. Select the table of interest and rename the variables
danger_table <- tables[[2]]
class(danger_table)
## [1] "data.frame"
danger_table[1:10,]
##                                     V1    V2
## 1                                 Name Image
## 2                             Abu Mena      
## 3      Air and Tenere Natural Reserves      
## 4               Ancient City of Aleppo      
## 5                Ancient City of Bosra      
## 6             Ancient City of Damascus      
## 7   Ancient Villages of Northern Syria      
## 8        Archaeological Site of Cyrene      
## 9  Archaeological Site of Leptis Magna      
## 10     Archaeological Site of Sabratha      
##                                                                                                                                                                          V3
## 1                                                                                                                                                                  Location
## 2                              EgyAbusir,<U+00A0>Egypt30°50′30″N 29°39′50″E<U+FEFF> / <U+FEFF>30.84167°N 29.66389°E<U+FEFF> / 30.84167; 29.66389<U+FEFF> (Abu Mena)
## 3              Niger1Arlit Department,<U+00A0>Niger18°17′N 8°0′E<U+FEFF> / <U+FEFF>18.283°N 8.000°E<U+FEFF> / 18.283; 8.000<U+FEFF> (Air and Tenere Natural Reserves)
## 4                      Aleppo Governorate, <U+00A0>Syria36°14′N 37°10′E<U+FEFF> / <U+FEFF>36.233°N 37.167°E<U+FEFF> / 36.233; 37.167<U+FEFF> (Ancient City of Aleppo)
## 5         Daraa Governorate, <U+00A0>Syria32°31′5″N 36°28′54″E<U+FEFF> / <U+FEFF>32.51806°N 36.48167°E<U+FEFF> / 32.51806; 36.48167<U+FEFF> (Ancient City of Bosra)
## 6  Damascus Governorate, <U+00A0>Syria33°30′41″N 36°18′23″E<U+FEFF> / <U+FEFF>33.51139°N 36.30639°E<U+FEFF> / 33.51139; 36.30639<U+FEFF> (Ancient City of Damascus)
## 7                       Syria36°20′3″N 36°50′39″E<U+FEFF> / <U+FEFF>36.33417°N 36.84417°E<U+FEFF> / 36.33417; 36.84417<U+FEFF> (Ancient Villages of Northern Syria)
## 8   LibJebel Akhdar,<U+00A0>Libya32°49′30″N 21°51′30″E<U+FEFF> / <U+FEFF>32.82500°N 21.85833°E<U+FEFF> / 32.82500; 21.85833<U+FEFF> (Archaeological Site of Cyrene)
## 9    LibKhoms,<U+00A0>Libya32°38′18″N 14°17′35″E<U+FEFF> / <U+FEFF>32.63833°N 14.29306°E<U+FEFF> / 32.63833; 14.29306<U+FEFF> (Archaeological Site of Leptis Magna)
## 10     LibSabratha,<U+00A0>Libya32°48′19″N 12°29′6″E<U+FEFF> / <U+FEFF>32.80528°N 12.48500°E<U+FEFF> / 32.80528; 12.48500<U+FEFF> (Archaeological Site of Sabratha)
##                               V4                     V5         V6           V7
## 1                       Criteria          Areaha (acre) Year (WHS)   Endangered
## 2                  Cultural:(iv)              182 (450)       1979 2001<U+2013>
## 3       Natural:(vii), (ix), (x) 7,736,000 (19,120,000)       1991 1992<U+2013>
## 4             Cultural:(iii)(iv)              350 (860)       1986 2013<U+2013>
## 5          Cultural:(i)(iii)(vi)               <U+2014>       1980 2013<U+2013>
## 6  Cultural:(i)(ii)(iii)(iv)(vi)               86 (210)       1979 2013<U+2013>
## 7          Cultural:(iii)(iv)(v)        12,290 (30,400)       2011 2013<U+2013>
## 8     Cultural:(ii), (iii), (vi)               <U+2014>       1982 2016<U+2013>
## 9      Cultural:(i), (ii), (iii)               <U+2014>       1982 2016<U+2013>
## 10                Cultural:(iii)               <U+2014>       1982 2016<U+2013>
##                                                                                                                                             V8
## 1                                                                                                                                       Reason
## 2                               Cave-ins in the area caused by the clay at the surface, which becomes semi-liquid when met with "excess water"
## 3  Military conflict and civil disturbance in the region as well as a reduction of wildlife population and degradation of the vegetation cover
## 4                                                  Syrian Civil War, currently held by the government. Bombings continue threatening the site.
## 5                                                                                                    Syrian Civil War, held by the government.
## 6                                Syrian Civil War, rebel gunfire and mortar shelling, mainly from adjacent Jobar suburb endangers foundations.
## 7                                                Syrian Civil War, some held by rebels. Reports of looting and demolitions by Islamist groups.
## 8                                                   Libyan Civil War, presence of armed groups, already incurred and potential further damage.
## 9                                                   Libyan Civil War, presence of armed groups, already incurred and potential further damage.
## 10                                                  Libyan Civil War, presence of armed groups, already incurred and potential further damage.
##              V9
## 1          Refs
## 2  [17][18][19]
## 3      [20][21]
## 4          [22]
## 5          [23]
## 6          [24]
## 7          [25]
## 8      [26][27]
## 9      [27][28]
## 10     [27][29]
names(danger_table)
## [1] "V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9"
danger_table <- danger_table[-1, c(1,3,4,6,7)]
danger_table
##                                                                                               V1
## 2                                                                                       Abu Mena
## 3                                                                Air and Tenere Natural Reserves
## 4                                                                         Ancient City of Aleppo
## 5                                                                          Ancient City of Bosra
## 6                                                                       Ancient City of Damascus
## 7                                                             Ancient Villages of Northern Syria
## 8                                                                  Archaeological Site of Cyrene
## 9                                                            Archaeological Site of Leptis Magna
## 10                                                               Archaeological Site of Sabratha
## 11                                                                        Ashur (Qal'at Sherqat)
## 12                                                                 Chan Chan Archaeological Zone
## 13                                                                                City of Potosi
## 14                                                                             Coro and its Port
## 15                                                  Crac des Chevaliers and Qal’at Salah El-Din
## 16                           Cultural Landscape and Archaeological Remains of the Bamiyan Valley
## 17                                                                                  East Rennell
## 18                                                                      Everglades National Park
## 19                         Fortifications on the Caribbean Side of Panama: Portobelo-San Lorenzo
## 20                                                                         Garamba National Park
## 21                                                                                         Hatra
## 22                                                                     Hebron/Al-Khalil Old Town
## 23                                                               Historic Centre of Shakhrisyabz
## 24                                                                     Historic Centre of Vienna
## 25                                                                 Historic Town of Zab<U+012B>d
## 26                                         Islands and Protected Areas of the Gulf of California
## 27                                                                    Kahuzi-Biega National Park
## 28                                                                   Lake Turkana National Parks
## 29                                                   Liverpool <U+2013> Maritime Mercantile City
## 30                                                         Manovo-Gounda St Floris National Park
## 31                                                     Minaret and Archaeological Remains of Jam
## 32                                                                  Medieval Monuments in Kosovo
## 33                                                             Mount Nimba Strict Nature Reserve
## 34                                            Nan Madol: Ceremonial Centre of Eastern Micronesia
## 35                                                                    Niokolo-Koba National Park
## 36                                                                        Okapi Wildlife Reserve
## 37                                                           Old City of Jerusalem and its Walls
## 38                                                                            Old City of Sana'a
## 39                                                                          Old Town of Ghadames
## 40                                                                           Old Towns of Djenne
## 41 Palestine: Land of Olives and Vines <U+2013> Cultural Landscape of Southern Jerusalem, Battir
## 42                                                                     Old Walled City of Shibam
## 43                                                                 Rainforests of the Atsinanana
## 44                                                                 Rio Platano Biosphere Reserve
## 45                                                              Rock-Art Sites of Tadrart Acacus
## 46                                                                         Salonga National Park
## 47                                                                   Samarra Archaeological City
## 48                                                                           Selous Game Reserve
## 49                                                                               Site of Palmyra
## 50                                                                                      Timbuktu
## 51                                                                                 Tomb of Askia
## 52                                                              Tombs of Buganda Kings at Kasubi
## 53                                                       Tropical Rainforest Heritage of Sumatra
## 54                                                                         Virunga National Park
##                                                                                                                                                                                                                                              V3
## 2                                                                                                  EgyAbusir,<U+00A0>Egypt30°50′30″N 29°39′50″E<U+FEFF> / <U+FEFF>30.84167°N 29.66389°E<U+FEFF> / 30.84167; 29.66389<U+FEFF> (Abu Mena)
## 3                                                                                  Niger1Arlit Department,<U+00A0>Niger18°17′N 8°0′E<U+FEFF> / <U+FEFF>18.283°N 8.000°E<U+FEFF> / 18.283; 8.000<U+FEFF> (Air and Tenere Natural Reserves)
## 4                                                                                          Aleppo Governorate, <U+00A0>Syria36°14′N 37°10′E<U+FEFF> / <U+FEFF>36.233°N 37.167°E<U+FEFF> / 36.233; 37.167<U+FEFF> (Ancient City of Aleppo)
## 5                                                                             Daraa Governorate, <U+00A0>Syria32°31′5″N 36°28′54″E<U+FEFF> / <U+FEFF>32.51806°N 36.48167°E<U+FEFF> / 32.51806; 36.48167<U+FEFF> (Ancient City of Bosra)
## 6                                                                      Damascus Governorate, <U+00A0>Syria33°30′41″N 36°18′23″E<U+FEFF> / <U+FEFF>33.51139°N 36.30639°E<U+FEFF> / 33.51139; 36.30639<U+FEFF> (Ancient City of Damascus)
## 7                                                                                           Syria36°20′3″N 36°50′39″E<U+FEFF> / <U+FEFF>36.33417°N 36.84417°E<U+FEFF> / 36.33417; 36.84417<U+FEFF> (Ancient Villages of Northern Syria)
## 8                                                                       LibJebel Akhdar,<U+00A0>Libya32°49′30″N 21°51′30″E<U+FEFF> / <U+FEFF>32.82500°N 21.85833°E<U+FEFF> / 32.82500; 21.85833<U+FEFF> (Archaeological Site of Cyrene)
## 9                                                                        LibKhoms,<U+00A0>Libya32°38′18″N 14°17′35″E<U+FEFF> / <U+FEFF>32.63833°N 14.29306°E<U+FEFF> / 32.63833; 14.29306<U+FEFF> (Archaeological Site of Leptis Magna)
## 10                                                                         LibSabratha,<U+00A0>Libya32°48′19″N 12°29′6″E<U+FEFF> / <U+FEFF>32.80528°N 12.48500°E<U+FEFF> / 32.80528; 12.48500<U+FEFF> (Archaeological Site of Sabratha)
## 11                                                                                              IraqSalah ad Din,<U+00A0>Iraq35°27′24″N 43°15′45″E<U+FEFF> / <U+FEFF>35.45667°N 43.26250°E<U+FEFF> / 35.45667; 43.26250<U+FEFF> (Ashur)
## 12                                                                           PerLa Libertad,<U+00A0>Peru8°6′40″S 79°4′30″W<U+FEFF> / <U+FEFF>8.11111°S 79.07500°W<U+FEFF> / -8.11111; -79.07500<U+FEFF> (Chan Chan Archaeological Zone)
## 13                                                                                                                 Potosi, <U+00A0>Bolivia\n19°35′1″S 65°45′11″W<U+FEFF> / <U+FEFF>19.58361°S 65.75306°W<U+FEFF> / -19.58361; -65.75306
## 14                                                                                                   VenFalcon,<U+00A0>Venezuela11°25′N 69°40′W<U+FEFF> / <U+FEFF>11.417°N 69.667°W<U+FEFF> / 11.417; -69.667<U+FEFF> (Coro and its Port)
## 15                                        Homs and Latakia Governorates, <U+00A0>Syria34°46′54″N 36°15′47″E<U+FEFF> / <U+FEFF>34.78167°N 36.26306°E<U+FEFF> / 34.78167; 36.26306<U+FEFF> (Crac des Chevaliers and Qal’at Salah El-Din)
## 16                                AfgBamyan,<U+00A0>Afghanistan34°49′55″N 67°49′36″E<U+FEFF> / <U+FEFF>34.83194°N 67.82667°E<U+FEFF> / 34.83194; 67.82667<U+FEFF> (Cultural Landscape and Archaeological Remains of the Bamiyan Valley)
## 17                                              Solomon IslandRennell and Bellona Province,<U+00A0>Solomon Islands11°40′59″S 160°10′59″E<U+FEFF> / <U+FEFF>11.68306°S 160.18306°E<U+FEFF> / -11.68306; 160.18306<U+FEFF> (East Rennell)
## 18                                                                             United StatesFlorida,<U+00A0>United States25°19′N 80°56′W<U+FEFF> / <U+FEFF>25.317°N 80.933°W<U+FEFF> / 25.317; -80.933<U+FEFF> (Everglades National Park)
## 19                             PanColon Province,<U+00A0>Panama9°33′14″N 79°39′21″W<U+FEFF> / <U+FEFF>9.55389°N 79.65583°W<U+FEFF> / 9.55389; -79.65583<U+FEFF> (Fortifications on the Caribbean Side of Panama: Portobelo-San Lorenzo)
## 20                                                                          DemOrientale,<U+00A0>Democratic Republic of the Congo4°0′N 29°15′E<U+FEFF> / <U+FEFF>4.000°N 29.250°E<U+FEFF> / 4.000; 29.250<U+FEFF> (Garamba National Park)
## 21                                                                                         IrqNineveh Governorate,<U+00A0>Iraq35°35′17″N 42°43′6″E<U+FEFF> / <U+FEFF>35.58806°N 42.71833°E<U+FEFF> / 35.58806; 42.71833<U+FEFF> (Hatra)
## 22                                                                 PalHebron Governorate,<U+00A0>Palestine31°31′27″N 35°6′32″E<U+FEFF> / <U+FEFF>31.52417°N 35.10889°E<U+FEFF> / 31.52417; 35.10889<U+FEFF> (Hebron/Al-Khalil Old Town)
## 23                                                            UzbQashqadaryo Region,<U+00A0>Uzbekistan39°3′0″N 66°50′0″E<U+FEFF> / <U+FEFF>39.05000°N 66.83333°E<U+FEFF> / 39.05000; 66.83333<U+FEFF> (Historic Centre of Shakhrisyabz)
## 24                                                                                                                AutVienna, <U+00A0>Austria48°12′N 16°22′E<U+FEFF> / <U+FEFF>48.200°N 16.367°E<U+FEFF> / 48.200; 16.367<U+FEFF> (Vienna)
## 25                                                                                       YemAl Hudaydah,<U+00A0>Yemen14°12′N 43°19′E<U+FEFF> / <U+FEFF>14.200°N 43.317°E<U+FEFF> / 14.200; 43.317<U+FEFF> (Historic Town of Zab<U+012B>d)
## 26 MexicoBaja California, Baja California Sur, Sonora, Sinaloa and Nayarit,<U+00A0>Mexico27°38′N 112°33′W<U+FEFF> / <U+FEFF>27.633°N 112.550°W<U+FEFF> / 27.633; -112.550<U+FEFF> (Islands and Protected Areas of the Gulf of California)
## 27                                                       DemSouth Kivuand Maniema,<U+00A0>Democratic Republic of the Congo2°30′S 28°45′E<U+FEFF> / <U+FEFF>2.500°S 28.750°E<U+FEFF> / -2.500; 28.750<U+FEFF> (Kahuzi-Biega National Park)
## 28                                                                                          Ken<U+00A0>Kenya3°3′8″N 36°30′13″E<U+FEFF> / <U+FEFF>3.05222°N 36.50361°E<U+FEFF> / 3.05222; 36.50361<U+FEFF> (Lake Turkana National Parks)
## 29                                  United KingdomLiverpoolEngland,<U+00A0>United Kingdom53°24′24″N 2°50′40″W<U+FEFF> / <U+FEFF>53.40667°N 2.84444°W<U+FEFF> / 53.40667; -2.84444<U+FEFF> (Liverpool <U+2013> Maritime Mercantile City)
## 30                                                          CenBamingui-Bangoran,<U+00A0>Central African Republic9°0′N 21°30′E<U+FEFF> / <U+FEFF>9.000°N 21.500°E<U+FEFF> / 9.000; 21.500<U+FEFF> (Manovo-Gounda St Floris National Park)
## 31                                                     AfgGh<U+014D>r,<U+00A0>Afghanistan34°23′48″N 64°30′58″E<U+FEFF> / <U+FEFF>34.39667°N 64.51611°E<U+FEFF> / 34.39667; 64.51611<U+FEFF> (Minaret and Archaeological Remains of Jam)
## 32                                                                                           Kosovo[a]42°39′40″N 20°15′56″E<U+FEFF> / <U+FEFF>42.66111°N 20.26556°E<U+FEFF> / 42.66111; 20.26556<U+FEFF> (Medieval Monuments in Kosovo)
## 33                                                            CotLola Prefecture,<U+00A0>Cote d'Ivoire*<U+00A0>Guinea*7°36′N 8°23′W<U+FEFF> / <U+FEFF>7.600°N 8.383°W<U+FEFF> / 7.600; -8.383<U+FEFF> (Mount Nimba Strict Nature Reserve)
## 34                                    MicronesiaTemwen Island,<U+00A0>Micronesia6°50′23″N 158°19′51″E<U+FEFF> / <U+FEFF>6.83972°N 158.33083°E<U+FEFF> / 6.83972; 158.33083<U+FEFF> (Nan Madol: Ceremonial Centre of Eastern Micronesia)
## 35                                                              SenTambacounda Regionand Kedougou Region,<U+00A0>Senegal13°0′N 12°40′W<U+FEFF> / <U+FEFF>13.000°N 12.667°W<U+FEFF> / 13.000; -12.667<U+FEFF> (Niokolo-Koba National Park)
## 36                                                                        Dem Orientale,<U+00A0>Democratic Republic of the Congo2°0′N 28°30′E<U+FEFF> / <U+FEFF>2.000°N 28.500°E<U+FEFF> / 2.000; 28.500<U+FEFF> (Okapi Wildlife Reserve)
## 37                                                 JerJerusalem(no nation named by UNESCO)[nb 3]31°46′36″N 35°14′3″E<U+FEFF> / <U+FEFF>31.77667°N 35.23417°E<U+FEFF> / 31.77667; 35.23417<U+FEFF> (Old City of Jerusalem and its Walls)
## 38                                                                                       YemSana'a Governorate,<U+00A0>Yemen15°21′20″N 44°12′29″E<U+FEFF> / <U+FEFF>15.35556°N 44.20806°E<U+FEFF> / 15.35556; 44.20806<U+FEFF> (Sana'a)
## 39                                                                                      LibGhadames,<U+00A0>Libya30°08′00″N 9°30′00″E<U+FEFF> / <U+FEFF>30.13333°N 9.50000°E<U+FEFF> / 30.13333; 9.50000<U+FEFF> (Old Town of Ghadames)
## 40                                                                                         MalDjenne,<U+00A0>Mali13°54′23″N 4°33′18″W<U+FEFF> / <U+FEFF>13.90639°N 4.55500°W<U+FEFF> / 13.90639; -4.55500<U+FEFF> (Old Towns of Djenne)
## 41        PalBattir, <U+00A0>Palestine31°43′11″N 35°7′50″E<U+FEFF> / <U+FEFF>31.71972°N 35.13056°E<U+FEFF> / 31.71972; 35.13056<U+FEFF> (Palestine: Land of Olives and Vines <U+2013> Cultural Landscape of Southern Jerusalem, Battir)
## 42                                                                                   YemHadhramaut Governorate,<U+00A0>Yemen15°55′37″N 48°37′36″E<U+FEFF> / <U+FEFF>15.92694°N 48.62667°E<U+FEFF> / 15.92694; 48.62667<U+FEFF> (Shibam)
## 43                                                                          MadEastern Madagascar,<U+00A0>Madagascar14°28′S 49°42′E<U+FEFF> / <U+FEFF>14.467°S 49.700°E<U+FEFF> / -14.467; 49.700<U+FEFF> (Rainforests of the Atsinanana)
## 44                                                                  HonLa Mosquitia,<U+00A0>Honduras15°44′40″N 84°40′30″W<U+FEFF> / <U+FEFF>15.74444°N 84.67500°W<U+FEFF> / 15.74444; -84.67500<U+FEFF> (Rio Platano Biosphere Reserve)
## 45                                                                                         LibFezzan,<U+00A0>Libya24°50′N 10°20′E<U+FEFF> / <U+FEFF>24.833°N 10.333°E<U+FEFF> / 24.833; 10.333<U+FEFF> (Rock-Art Sites of Tadrart Acacus)
## 46                                                                            DemEquateurand Bandundu Province,<U+00A0>Democratic Republic of the Congo2°S 21°E<U+FEFF> / <U+FEFF>2°S 21°E<U+FEFF> / -2; 21<U+FEFF> (Salonga National Park)
## 47                                                                                        IraqSalah ad Din,<U+00A0>Iraq34°12′N 43°52′E<U+FEFF> / <U+FEFF>34.200°N 43.867°E<U+FEFF> / 34.200; 43.867<U+FEFF> (Samarra Archaeological City)
## 48                                                                 TanzaniaCoast, Morogoro, Lindi, Mtwara and Ruvuma Regions,\n<U+00A0>Tanzania,\n9°0′0″S 37°24′0″E<U+FEFF> / <U+FEFF>9.00000°S 37.40000°E<U+FEFF> / -9.00000; 37.40000
## 49                                                                                   Homs Governorate, <U+00A0>Syria34°33′15″N 38°16′0″E<U+FEFF> / <U+FEFF>34.55417°N 38.26667°E<U+FEFF> / 34.55417; 38.26667<U+FEFF> (Site of Palmyra)
## 50                                                                                 MaliTimbuktu,Timbuktu Region,<U+00A0>Mali16°46′24″N 2°59′58″W<U+FEFF> / <U+FEFF>16.77333°N 2.99944°W<U+FEFF> / 16.77333; -2.99944<U+FEFF> (Timbuktu)
## 51                                                                                      MaliGao,Gao Region,<U+00A0>Mali16°17′23″N 0°02′40″W<U+FEFF> / <U+FEFF>16.28972°N 0.04444°W<U+FEFF> / 16.28972; -0.04444<U+FEFF> (Tomb of Askia)
## 52                                                              UgandaKampala District,<U+00A0>Uganda0°19′45″N 32°33′12″E<U+FEFF> / <U+FEFF>0.32917°N 32.55333°E<U+FEFF> / 0.32917; 32.55333<U+FEFF> (Tombs of Buganda Kings at Kasubi)
## 53                                                                     IndonesiaSumatra,<U+00A0>Indonesia02°30′S 101°30′E<U+FEFF> / <U+FEFF>2.500°S 101.500°E<U+FEFF> / -2.500; 101.500<U+FEFF> (Tropical Rainforest Heritage of Sumatra)
## 54                                                           DemNorth Kivuand Orientale,<U+00A0>Democratic Republic of the Congo0°55′N 29°10′E<U+FEFF> / <U+FEFF>0.917°N 29.167°E<U+FEFF> / 0.917; 29.167<U+FEFF> (Virunga National Park)
##                                       V4   V6                             V7
## 2                          Cultural:(iv) 1979                   2001<U+2013>
## 3               Natural:(vii), (ix), (x) 1991                   1992<U+2013>
## 4                     Cultural:(iii)(iv) 1986                   2013<U+2013>
## 5                  Cultural:(i)(iii)(vi) 1980                   2013<U+2013>
## 6          Cultural:(i)(ii)(iii)(iv)(vi) 1979                   2013<U+2013>
## 7                  Cultural:(iii)(iv)(v) 2011                   2013<U+2013>
## 8             Cultural:(ii), (iii), (vi) 1982                   2016<U+2013>
## 9              Cultural:(i), (ii), (iii) 1982                   2016<U+2013>
## 10                        Cultural:(iii) 1982                   2016<U+2013>
## 11                  Cultural:(iii), (iv) 2003                   2003<U+2013>
## 12                   Cultural:(i), (iii) 1986                   1986<U+2013>
## 13           Cultural:\n(ii), (iv), (vi) 1987                   2014<U+2013>
## 14                    Cultural:(iv), (v) 1993                   2005<U+2013>
## 15                     Cultural:(ii)(iv) 2006                   2013<U+2013>
## 16 Cultural:(i), (ii), (iii), (iv), (vi) 2003                   2003<U+2013>
## 17                          Natural:(ix) 1998                   2013<U+2013>
## 18             Natural:(viii), (ix), (x) 1979 1993<U+2013>2007, 2010<U+2013>
## 19                    Cultural:(i), (iv) 1980                   2012<U+2013>
## 20                    Natural:(vii), (x) 1980 1984<U+2013>1992, 1996<U+2013>
## 21      Cultural:(ii), (iii), (iv), (vi) 1985                   2015<U+2013>
## 22             Cultural:(ii), (iv), (vi) 2017                   2017<U+2013>
## 23                  Cultural:(iii), (iv) 2000                   2016<U+2013>
## 24                 Cultural:(ii)(iv)(vi) 2001                   2017<U+2013>
## 25             Cultural:(ii), (iv), (vi) 1993                   2000<U+2013>
## 26              Natural:(vii), (ix), (x) 2005                   2019<U+2013>
## 27                           Natural:(x) 1980                   1997<U+2013>
## 28                     Natural:(viii)(x) 1997                   2018<U+2013>
## 29            Cultural:(ii), (iii), (iv) 2004                   2012<U+2013>
## 30                     Natural:(ix), (x) 1988                   1997<U+2013>
## 31            Cultural:(ii), (iii), (iv) 2002                   2002<U+2013>
## 32            Cultural:(ii), (iii), (iv) 2004                   2006<U+2013>
## 33                     Natural:(ix), (x) 1981                   1992<U+2013>
## 34       Cultural:(i), (iii), (iv), (vi) 2016                   2016<U+2013>
## 35                           Natural:(x) 1981                   2007<U+2013>
## 36                           Natural:(x) 1996                   1997<U+2013>
## 37           Cultural: (ii), (iii), (vi) 1981                   1982<U+2013>
## 38              Cultural:(iv), (v), (vi) 1986                   2015<U+2013>
## 39                          Cultural:(v) 1986                   2016<U+2013>
## 40                  Cultural:(iii), (iv) 1988                   2016<U+2013>
## 41                      Cultural:(iv)(v) 2014                   2014<U+2013>
## 42             Cultural:(iii), (iv), (v) 1982                   2015<U+2013>
## 43                     Natural:(ix), (x) 2007                   2010<U+2013>
## 44      Natural:(vii), (viii), (ix), (x) 1982 1996<U+2013>2007, 2011<U+2013>
## 45                        Cultural:(iii) 1985                   2016<U+2013>
## 46                   Natural:(vii), (ix) 1984                   1999<U+2013>
## 47            Cultural:(ii), (iii), (iv) 2007                   2007<U+2013>
## 48                   Natural:\n(ix), (x) 1982                   2014<U+2013>
## 49                  Cultural:(i)(ii)(iv) 1980                   2013<U+2013>
## 50              Cultural:(ii), (iv), (v) 1988                   2012<U+2013>
## 51            Cultural:(ii), (iii), (iv) 2004                   2012<U+2013>
## 52        Cultural:(i), (iii),(iv), (vi) 2001                   2010<U+2013>
## 53              Natural:(vii), (ix), (x) 2004                   2011<U+2013>
## 54            Natural:(vii), (viii), (x) 1979                   1994<U+2013>
colnames(danger_table) <- c("name","location","criterion","year_des","year_end")
head(danger_table)
##                                 name
## 2                           Abu Mena
## 3    Air and Tenere Natural Reserves
## 4             Ancient City of Aleppo
## 5              Ancient City of Bosra
## 6           Ancient City of Damascus
## 7 Ancient Villages of Northern Syria
##                                                                                                                                                                   location
## 2                             EgyAbusir,<U+00A0>Egypt30°50′30″N 29°39′50″E<U+FEFF> / <U+FEFF>30.84167°N 29.66389°E<U+FEFF> / 30.84167; 29.66389<U+FEFF> (Abu Mena)
## 3             Niger1Arlit Department,<U+00A0>Niger18°17′N 8°0′E<U+FEFF> / <U+FEFF>18.283°N 8.000°E<U+FEFF> / 18.283; 8.000<U+FEFF> (Air and Tenere Natural Reserves)
## 4                     Aleppo Governorate, <U+00A0>Syria36°14′N 37°10′E<U+FEFF> / <U+FEFF>36.233°N 37.167°E<U+FEFF> / 36.233; 37.167<U+FEFF> (Ancient City of Aleppo)
## 5        Daraa Governorate, <U+00A0>Syria32°31′5″N 36°28′54″E<U+FEFF> / <U+FEFF>32.51806°N 36.48167°E<U+FEFF> / 32.51806; 36.48167<U+FEFF> (Ancient City of Bosra)
## 6 Damascus Governorate, <U+00A0>Syria33°30′41″N 36°18′23″E<U+FEFF> / <U+FEFF>33.51139°N 36.30639°E<U+FEFF> / 33.51139; 36.30639<U+FEFF> (Ancient City of Damascus)
## 7                      Syria36°20′3″N 36°50′39″E<U+FEFF> / <U+FEFF>36.33417°N 36.84417°E<U+FEFF> / 36.33417; 36.84417<U+FEFF> (Ancient Villages of Northern Syria)
##                       criterion year_des     year_end
## 2                 Cultural:(iv)     1979 2001<U+2013>
## 3      Natural:(vii), (ix), (x)     1991 1992<U+2013>
## 4            Cultural:(iii)(iv)     1986 2013<U+2013>
## 5         Cultural:(i)(iii)(vi)     1980 2013<U+2013>
## 6 Cultural:(i)(ii)(iii)(iv)(vi)     1979 2013<U+2013>
## 7         Cultural:(iii)(iv)(v)     2011 2013<U+2013>
  1. Data cleaning
# install.packages("stringr")
library(stringr)

danger_table$criterion[1:3]
## [1] "Cultural:(iv)"            "Natural:(vii), (ix), (x)"
## [3] "Cultural:(iii)(iv)"
danger_table$criterion <- ifelse(str_detect(danger_table$criterion, "Natural")==TRUE, "Natural", "Cultural")
danger_table$criterion[1:3]
## [1] "Cultural" "Natural"  "Cultural"
danger_table$year_des[1:3]
## [1] "1979" "1991" "1986"
danger_table$year_des <- as.numeric(danger_table$year_des)
danger_table$year_des[1:3]
## [1] 1979 1991 1986
danger_table$year_end[1:10]
##  [1] "2001<U+2013>" "1992<U+2013>" "2013<U+2013>" "2013<U+2013>" "2013<U+2013>" "2013<U+2013>" "2016<U+2013>" "2016<U+2013>" "2016<U+2013>"
## [10] "2003<U+2013>"
year_end_clean <- unlist(str_extract_all(danger_table$year_end, "^[[:digit:]]{4}"))
danger_table$year_end <- as.numeric(year_end_clean)
danger_table$year_end[1:10]
##  [1] 2001 1992 2013 2013 2013 2013 2016 2016 2016 2003

The location variable contains the name of the site’s location, the country, and the geographic coordinates in several varieties.

danger_table$location[c(1, 3, 5)]
## [1] "EgyAbusir,<U+00A0>Egypt30°50′30″N 29°39′50″E<U+FEFF> / <U+FEFF>30.84167°N 29.66389°E<U+FEFF> / 30.84167; 29.66389<U+FEFF> (Abu Mena)"
## [2] "Aleppo Governorate, <U+00A0>Syria36°14′N 37°10′E<U+FEFF> / <U+FEFF>36.233°N 37.167°E<U+FEFF> / 36.233; 37.167<U+FEFF> (Ancient City of Aleppo)"
## [3] "Damascus Governorate, <U+00A0>Syria33°30′41″N 36°18′23″E<U+FEFF> / <U+FEFF>33.51139°N 36.30639°E<U+FEFF> / 33.51139; 36.30639<U+FEFF> (Ancient City of Damascus)"
reg_y <- "[/][ -]*[[:digit:]]*[.]*[[:digit:]]*[;]"
reg_x <- "[;][ -]*[[:digit:]]*[.]*[[:digit:]]*"
y_coords <- str_extract(danger_table$location, reg_y)
y_coords
##  [1] "/ 30.84167;"  "/ 18.283;"    "/ 36.233;"    "/ 32.51806;"  "/ 33.51139;" 
##  [6] "/ 36.33417;"  "/ 32.82500;"  "/ 32.63833;"  "/ 32.80528;"  "/ 35.45667;" 
## [11] "/ -8.11111;"  "/ -19.58361;" "/ 11.417;"    "/ 34.78167;"  "/ 34.83194;" 
## [16] "/ -11.68306;" "/ 25.317;"    "/ 9.55389;"   "/ 4.000;"     "/ 35.58806;" 
## [21] "/ 31.52417;"  "/ 39.05000;"  "/ 48.200;"    "/ 14.200;"    "/ 27.633;"   
## [26] "/ -2.500;"    "/ 3.05222;"   "/ 53.40667;"  "/ 9.000;"     "/ 34.39667;" 
## [31] "/ 42.66111;"  "/ 7.600;"     "/ 6.83972;"   "/ 13.000;"    "/ 2.000;"    
## [36] "/ 31.77667;"  "/ 15.35556;"  "/ 30.13333;"  "/ 13.90639;"  "/ 31.71972;" 
## [41] "/ 15.92694;"  "/ -14.467;"   "/ 15.74444;"  "/ 24.833;"    "/ -2;"       
## [46] "/ 34.200;"    "/ -9.00000;"  "/ 34.55417;"  "/ 16.77333;"  "/ 16.28972;" 
## [51] "/ 0.32917;"   "/ -2.500;"    "/ 0.917;"
y_coords <- as.numeric(str_sub(y_coords, 3, -2))
y_coords
##  [1]  30.84167  18.28300  36.23300  32.51806  33.51139  36.33417  32.82500
##  [8]  32.63833  32.80528  35.45667  -8.11111 -19.58361  11.41700  34.78167
## [15]  34.83194 -11.68306  25.31700   9.55389   4.00000  35.58806  31.52417
## [22]  39.05000  48.20000  14.20000  27.63300  -2.50000   3.05222  53.40667
## [29]   9.00000  34.39667  42.66111   7.60000   6.83972  13.00000   2.00000
## [36]  31.77667  15.35556  30.13333  13.90639  31.71972  15.92694 -14.46700
## [43]  15.74444  24.83300  -2.00000  34.20000  -9.00000  34.55417  16.77333
## [50]  16.28972   0.32917  -2.50000   0.91700
danger_table$y_coords <- y_coords

x_coords <- str_extract(danger_table$location, reg_x)
x_coords
##  [1] "; 29.66389"  "; 8.000"     "; 37.167"    "; 36.48167"  "; 36.30639" 
##  [6] "; 36.84417"  "; 21.85833"  "; 14.29306"  "; 12.48500"  "; 43.26250" 
## [11] "; -79.07500" "; -65.75306" "; -69.667"   "; 36.26306"  "; 67.82667" 
## [16] "; 160.18306" "; -80.933"   "; -79.65583" "; 29.250"    "; 42.71833" 
## [21] "; 35.10889"  "; 66.83333"  "; 16.367"    "; 43.317"    "; -112.550" 
## [26] "; 28.750"    "; 36.50361"  "; -2.84444"  "; 21.500"    "; 64.51611" 
## [31] "; 20.26556"  "; -8.383"    "; 158.33083" "; -12.667"   "; 28.500"   
## [36] "; 35.23417"  "; 44.20806"  "; 9.50000"   "; -4.55500"  "; 35.13056" 
## [41] "; 48.62667"  "; 49.700"    "; -84.67500" "; 10.333"    "; 21"       
## [46] "; 43.867"    "; 37.40000"  "; 38.26667"  "; -2.99944"  "; -0.04444" 
## [51] "; 32.55333"  "; 101.500"   "; 29.167"
x_coords <- as.numeric(str_sub(x_coords, 3, -1))
x_coords
##  [1]   29.66389    8.00000   37.16700   36.48167   36.30639   36.84417
##  [7]   21.85833   14.29306   12.48500   43.26250  -79.07500  -65.75306
## [13]  -69.66700   36.26306   67.82667  160.18306  -80.93300  -79.65583
## [19]   29.25000   42.71833   35.10889   66.83333   16.36700   43.31700
## [25] -112.55000   28.75000   36.50361   -2.84444   21.50000   64.51611
## [31]   20.26556   -8.38300  158.33083  -12.66700   28.50000   35.23417
## [37]   44.20806    9.50000   -4.55500   35.13056   48.62667   49.70000
## [43]  -84.67500   10.33300   21.00000   43.86700   37.40000   38.26667
## [49]   -2.99944   -0.04444   32.55333  101.50000   29.16700
danger_table$x_coords <- x_coords
danger_table$location <- NULL
danger_table
##                                                                                             name
## 2                                                                                       Abu Mena
## 3                                                                Air and Tenere Natural Reserves
## 4                                                                         Ancient City of Aleppo
## 5                                                                          Ancient City of Bosra
## 6                                                                       Ancient City of Damascus
## 7                                                             Ancient Villages of Northern Syria
## 8                                                                  Archaeological Site of Cyrene
## 9                                                            Archaeological Site of Leptis Magna
## 10                                                               Archaeological Site of Sabratha
## 11                                                                        Ashur (Qal'at Sherqat)
## 12                                                                 Chan Chan Archaeological Zone
## 13                                                                                City of Potosi
## 14                                                                             Coro and its Port
## 15                                                  Crac des Chevaliers and Qal’at Salah El-Din
## 16                           Cultural Landscape and Archaeological Remains of the Bamiyan Valley
## 17                                                                                  East Rennell
## 18                                                                      Everglades National Park
## 19                         Fortifications on the Caribbean Side of Panama: Portobelo-San Lorenzo
## 20                                                                         Garamba National Park
## 21                                                                                         Hatra
## 22                                                                     Hebron/Al-Khalil Old Town
## 23                                                               Historic Centre of Shakhrisyabz
## 24                                                                     Historic Centre of Vienna
## 25                                                                 Historic Town of Zab<U+012B>d
## 26                                         Islands and Protected Areas of the Gulf of California
## 27                                                                    Kahuzi-Biega National Park
## 28                                                                   Lake Turkana National Parks
## 29                                                   Liverpool <U+2013> Maritime Mercantile City
## 30                                                         Manovo-Gounda St Floris National Park
## 31                                                     Minaret and Archaeological Remains of Jam
## 32                                                                  Medieval Monuments in Kosovo
## 33                                                             Mount Nimba Strict Nature Reserve
## 34                                            Nan Madol: Ceremonial Centre of Eastern Micronesia
## 35                                                                    Niokolo-Koba National Park
## 36                                                                        Okapi Wildlife Reserve
## 37                                                           Old City of Jerusalem and its Walls
## 38                                                                            Old City of Sana'a
## 39                                                                          Old Town of Ghadames
## 40                                                                           Old Towns of Djenne
## 41 Palestine: Land of Olives and Vines <U+2013> Cultural Landscape of Southern Jerusalem, Battir
## 42                                                                     Old Walled City of Shibam
## 43                                                                 Rainforests of the Atsinanana
## 44                                                                 Rio Platano Biosphere Reserve
## 45                                                              Rock-Art Sites of Tadrart Acacus
## 46                                                                         Salonga National Park
## 47                                                                   Samarra Archaeological City
## 48                                                                           Selous Game Reserve
## 49                                                                               Site of Palmyra
## 50                                                                                      Timbuktu
## 51                                                                                 Tomb of Askia
## 52                                                              Tombs of Buganda Kings at Kasubi
## 53                                                       Tropical Rainforest Heritage of Sumatra
## 54                                                                         Virunga National Park
##    criterion year_des year_end  y_coords   x_coords
## 2   Cultural     1979     2001  30.84167   29.66389
## 3    Natural     1991     1992  18.28300    8.00000
## 4   Cultural     1986     2013  36.23300   37.16700
## 5   Cultural     1980     2013  32.51806   36.48167
## 6   Cultural     1979     2013  33.51139   36.30639
## 7   Cultural     2011     2013  36.33417   36.84417
## 8   Cultural     1982     2016  32.82500   21.85833
## 9   Cultural     1982     2016  32.63833   14.29306
## 10  Cultural     1982     2016  32.80528   12.48500
## 11  Cultural     2003     2003  35.45667   43.26250
## 12  Cultural     1986     1986  -8.11111  -79.07500
## 13  Cultural     1987     2014 -19.58361  -65.75306
## 14  Cultural     1993     2005  11.41700  -69.66700
## 15  Cultural     2006     2013  34.78167   36.26306
## 16  Cultural     2003     2003  34.83194   67.82667
## 17   Natural     1998     2013 -11.68306  160.18306
## 18   Natural     1979     1993  25.31700  -80.93300
## 19  Cultural     1980     2012   9.55389  -79.65583
## 20   Natural     1980     1984   4.00000   29.25000
## 21  Cultural     1985     2015  35.58806   42.71833
## 22  Cultural     2017     2017  31.52417   35.10889
## 23  Cultural     2000     2016  39.05000   66.83333
## 24  Cultural     2001     2017  48.20000   16.36700
## 25  Cultural     1993     2000  14.20000   43.31700
## 26   Natural     2005     2019  27.63300 -112.55000
## 27   Natural     1980     1997  -2.50000   28.75000
## 28   Natural     1997     2018   3.05222   36.50361
## 29  Cultural     2004     2012  53.40667   -2.84444
## 30   Natural     1988     1997   9.00000   21.50000
## 31  Cultural     2002     2002  34.39667   64.51611
## 32  Cultural     2004     2006  42.66111   20.26556
## 33   Natural     1981     1992   7.60000   -8.38300
## 34  Cultural     2016     2016   6.83972  158.33083
## 35   Natural     1981     2007  13.00000  -12.66700
## 36   Natural     1996     1997   2.00000   28.50000
## 37  Cultural     1981     1982  31.77667   35.23417
## 38  Cultural     1986     2015  15.35556   44.20806
## 39  Cultural     1986     2016  30.13333    9.50000
## 40  Cultural     1988     2016  13.90639   -4.55500
## 41  Cultural     2014     2014  31.71972   35.13056
## 42  Cultural     1982     2015  15.92694   48.62667
## 43   Natural     2007     2010 -14.46700   49.70000
## 44   Natural     1982     1996  15.74444  -84.67500
## 45  Cultural     1985     2016  24.83300   10.33300
## 46   Natural     1984     1999  -2.00000   21.00000
## 47  Cultural     2007     2007  34.20000   43.86700
## 48   Natural     1982     2014  -9.00000   37.40000
## 49  Cultural     1980     2013  34.55417   38.26667
## 50  Cultural     1988     2012  16.77333   -2.99944
## 51  Cultural     2004     2012  16.28972   -0.04444
## 52  Cultural     2001     2010   0.32917   32.55333
## 53   Natural     2004     2011  -2.50000  101.50000
## 54   Natural     1979     1994   0.91700   29.16700
round(danger_table$y_coords, 2)[1:3]
## [1] 30.84 18.28 36.23
round(danger_table$x_coords, 2)[1:3]
## [1] 29.66  8.00 37.17
length(danger_table$y_coords)
## [1] 53
length(danger_table$x_coords)
## [1] 53
dim(danger_table)
## [1] 53  6
head(danger_table)
##                                 name criterion year_des year_end y_coords
## 2                           Abu Mena  Cultural     1979     2001 30.84167
## 3    Air and Tenere Natural Reserves   Natural     1991     1992 18.28300
## 4             Ancient City of Aleppo  Cultural     1986     2013 36.23300
## 5              Ancient City of Bosra  Cultural     1980     2013 32.51806
## 6           Ancient City of Damascus  Cultural     1979     2013 33.51139
## 7 Ancient Villages of Northern Syria  Cultural     2011     2013 36.33417
##   x_coords
## 2 29.66389
## 3  8.00000
## 4 37.16700
## 5 36.48167
## 6 36.30639
## 7 36.84417
  1. Plot the locations of the places on a map
# install.packages("maps")
library(maps)

pch <- ifelse(danger_table$criterion == "Natural", 19, 2)
map("world", col = "darkgrey", lwd = 0.5, mar = c(0.1, 0.1, 0.1, 0.1))
points(danger_table$x_coords, danger_table$y_coords, pch = pch)
box()

  1. Analytic approaches to answer the questions
table(danger_table$criterion)
## 
## Cultural  Natural 
##       36       17
  1. Visualization of time trends
#install.packages("tidyverse")
#install.packages("ggplot2")
library(tidyverse)
library(ggplot2)

danger_table %>% 
  ggplot(aes(x=year_end)) +
  geom_histogram(binwidth = 5) +
  xlab("Year when site was put on the list of endangered sites")