Mô tả: Dữ liệu Journals của gói AER là một dữ liệu Đăng ký các tạp chí kinh tế tại các thư viện Hoa Kỳ, cho năm 2000, trong đó gồm 10 biến.

1.title : tên tạp chí.

2.publisher : yếu tố với tên nhà xuất bản.

3.society : nhân tố. Là tạp chí được xuất bản bởi một xã hội học thuật?

4.price : Giá đăng ký thư viện.

5.pages : Số trang

6.charpp : Ký tự trên mỗi trang.

7.citations : Tổng số trích dẫn.

8.foundingyear : Tạp chí năm được thành lập.

9.subs : Số lượng đăng ký thư viện.

10.field : yếu tố với mô tả trường.

1 Bài thực hành tuần 7

1.1 Function xử lý công việc

1.1.1 Function là gì ?

Function (Hàm) là một tập hợp những đoạn mã dùng để thực hiện một nhiệm vụ nào đó. Nó có thể được gọi và tái sử dụng nhiều lần. Bạn có thể chuyển thông tin vào một hàm. Đồng thời, nó cũng có thể gửi trả thông tin trở lại. Nhiều ngôn ngữ lập trình có các hàm dựng sẵn mà người dùng chỉ cần lấy từ thư viện hàm. Ngoài ra, bạn cũng có thể tự tạo ra các hàm theo mục đích của riêng mình.Dưới đây là một số ví dụ

1.1.2 Hàm tính tổng

tong = function(x){
  sum  = 0
  for(i in 1:length(x)) {
    sum  = sum + x[i]
  }
  return(sum)
}
x  = c(1,3,4,2,5,6,7)
tong(x)
## [1] 28
sum(x) # Sử dụng hàm sum() để kiểm tra lại
## [1] 28

1.1.3 Hàm tính trung bình

trung_binh = function(x){
  mean  = tong(x)/length(x)
  return(mean)
}
x  = c(1,3,4,6,7,3,2)
trung_binh(x)
## [1] 3.714286
mean(x) # Sử dụng hàm mean() để kiểm tra lại
## [1] 3.714286

1.1.4 Hàm tung xúc xắc

toss.die  = function(){
  x = runif(1)
  if(x <=1/6) 1 else{
    if(x <= 2/6) 2 else{
      if(x <=3/6 )3 else{
        if(x <=4/6) 4 else{
          if(x <=5/6) 5 else 6
        }
      }
    }
  }
}
sample.die =  function(n){
  replicate(n,toss.die())
}
X = sample.die(1000)
table(X)/length(X) #Tần suất xuất hiện của từng mặt trong n lần tung
## X
##     1     2     3     4     5     6 
## 0.173 0.170 0.181 0.160 0.161 0.155

1.1.5 Giải phương trình bậc 2

solve_2 = function(a,b,c){
  if(a==0){
    if(b==0 & c==0){
      print("Phuong trinh vo so nghiem")
    }
    if(b==0 & c != 0 ){
      print("Phuong trinh vo nghiem")
    }
    else {
      print("Phuong trinh co nghiem :")
      print(-c/b)
    }
  }
  else{
    delta = b^2-4*a*c
    if(delta <0){
      print("Phuong trinh vo nghiem")
    }
     else if(delta == 0){
      x = -b/(2*a)
      print("Phuong trinh co nghiem kep x = ")
      print(x)
    }
    else if(delta > 0 ){
      x1 = (-b + sqrt(delta))/(2*a)
      x2 = (-b - sqrt(delta))/(2*a)
      print("Phuong trinh co 2 nghiem phan biet:")
      print(x1)
      print(x2)
    }
  }
}
solve_2(1,2,3)
## [1] "Phuong trinh vo nghiem"
solve_2(1,3,-5)
## [1] "Phuong trinh co 2 nghiem phan biet:"
## [1] 1.192582
## [1] -4.192582
solve_2(1,-4,4)
## [1] "Phuong trinh co nghiem kep x = "
## [1] 2

1.2 WEB SCRAPING DATA

Web Scraping là gì ?

Web scraping, web harvesting hay còn gọi là web data extraction là quá trình cào dữ liệu được sử dụng để trích xuất dữ liệu từ các website. Các phần mềm web scraping truy cập vào website bằng giao thức HTTP hoặc bằng web browser để lấy ra các dữ liệu mà họ quan tâm. Quá trình này có thể được thực hiện thủ công bằng cách sử dụng phần mềm, tuy nhiên phần lớn khi nhắc đến web scraping tương đương với quá trình thu thập dữ liệu tự động được triển khai bằng bot hoặc các web crawler.

Web Scraper dùng để làm gì?

Những công dụng của web scraping là gì? Đến đây, bạn có thể nghĩ ra một số cách khác nhau để sử dụng web scraper. Chúng tôi đã đặt một trong số những cái phổ biến nhất bên dưới.

Scraping giá cổ phiếu vào app API.

Scraping dữ liệu từ YellowPages để tạo khách hàng tiềm năng.

Scraping dữ liệu từ công cụ định vị cửa hàng để tạo danh sách các địa điểm kinh doanh.

Scraping các sản phẩm từ các website như Amazon hoặc eBay để phân tích đối thủ cạnh tranh.

Scraping số liệu thống kê thể thao để cá cược.

Scraping dữ liệu trang web trước khi chuyển đến website đó.

Scraping chi tiết sản phẩm để so sánh và mua sắm.

Scraping dữ liệu tài chính để nghiên cứu thị trường và thông tin chi tiết.

library(rvest)
## Warning: package 'rvest' was built under R version 4.3.1
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.1
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
read_html("https://www.investing.com/indices/world-indices")
## {html_document}
## <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:schema="http://schema.org/" class="com" lang="en" geo="VN">
##  [1] <head>\n<link rel="dns-prefetch" href="https://i-invdn-com.investing.com ...
##  [2] <body class="takeover dfpTakeovers ">\n\n<noscript>\n        <iframe src ...
##  [3] <img src="https://secure.adnxs.com/seg?t=2&amp;add=19833489" width="1" h ...
##  [4] <script>var TimeZoneID = +"8";window.timezoneOffset = +"-14400";window.s ...
##  [5] <script>window.uid = 0</script>
##  [6] <script>\n\n\t\t\t$(function(){\n\t\t\t\t$(window).trigger("socketRetry" ...
##  [7] <script>function refresher() { void (0);}</script>
##  [8] <script>\n    \tvar _comscore = _comscore || [];\n    \t_comscore.push(\ ...
##  [9] <script type="text/javascript">\n                var google_conversion_i ...
## [10] <script type="text/javascript" src="//www.googleadservices.com/pagead/co ...
## [11] <noscript><div style="display:inline;"><img height="1" width="1" style=" ...
## [12] <script type="text/javascript">\n        fbq = window.fbq || $.noop;\n   ...
## [13] <script>\n    $(function () {\n        $('.googleButtonWrapper').hover(f ...
## [14] <div id="g_id_onload" data-client_id="606447380154-9825jtap5as2sm0f868m5 ...
html_doc<-read_html("https://www.investing.com/indices/world-indices")
table <- html_nodes(html_doc,xpath = '//*[@id="indice_table_37"]')
html_table(table)
## [[1]]
## # A tibble: 2 × 9
##   ``    Index                     Last  High  Low      Chg. `Chg. %` Time  ``   
##   <lgl> <chr>                     <chr> <chr> <chr>   <dbl> <chr>    <chr> <lgl>
## 1 NA    S&P Merval                443,… 452,… 439,… -7.83e3 -1.74%   14/07 NA   
## 2 NA    S&P/BYMA Argentina Gener… 18,7… 19,0… 18,5… -3.08e5 -1.62%   14/07 NA
argentina <- html_table(table)[[1]]
argentina_table <- argentina[,c(-1,-9)]
argentina_table
## # A tibble: 2 × 7
##   Index                      Last       High       Low       Chg. `Chg. %` Time 
##   <chr>                      <chr>      <chr>      <chr>    <dbl> <chr>    <chr>
## 1 S&P Merval                 443,303.59 452,014.47 439,5… -7.83e3 -1.74%   14/07
## 2 S&P/BYMA Argentina General 18,700,800 19,015,372 18,56… -3.08e5 -1.62%   14/07
html_doc2<-read_html("https://www.investing.com/indices/world-indices")
html_doc2
## {html_document}
## <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:schema="http://schema.org/" class="com" lang="en" geo="VN">
##  [1] <head>\n<link rel="dns-prefetch" href="https://i-invdn-com.investing.com ...
##  [2] <body class="takeover dfpTakeovers ">\n\n<noscript>\n        <iframe src ...
##  [3] <img src="https://secure.adnxs.com/seg?t=2&amp;add=19833489" width="1" h ...
##  [4] <script>var TimeZoneID = +"8";window.timezoneOffset = +"-14400";window.s ...
##  [5] <script>window.uid = 0</script>
##  [6] <script>\n\n\t\t\t$(function(){\n\t\t\t\t$(window).trigger("socketRetry" ...
##  [7] <script>function refresher() { void (0);}</script>
##  [8] <script>\n    \tvar _comscore = _comscore || [];\n    \t_comscore.push(\ ...
##  [9] <script type="text/javascript">\n                var google_conversion_i ...
## [10] <script type="text/javascript" src="//www.googleadservices.com/pagead/co ...
## [11] <noscript><div style="display:inline;"><img height="1" width="1" style=" ...
## [12] <script type="text/javascript">\n        fbq = window.fbq || $.noop;\n   ...
## [13] <script>\n    $(function () {\n        $('.googleButtonWrapper').hover(f ...
## [14] <div id="g_id_onload" data-client_id="606447380154-9825jtap5as2sm0f868m5 ...
company_names  <- html_nodes(html_doc2,xpath = '//*[@id="marketMoversBoxWrapper"]')
company_tables <- html_table(company_names)
companies <- company_tables[[1]]
companies <- companies[,c(-1,-7)]
companies
## # A tibble: 23 × 5
##    Name  Last   `Chg. %` Vol.    ``   
##    <chr> <chr>  <chr>    <chr>   <lgl>
##  1 TSLA  281.38 +1.25%   120.06M NA   
##  2 AMD   115.94 +0.02%   91.69M  NA   
##  3 NVDA  454.69 -1.10%   77.21M  NA   
##  4 AMZN  134.68 +0.28%   53.54M  NA   
##  5 AAPL  190.69 +0.08%   40.76M  NA   
##  6 MSFT  345.24 +0.75%   27.97M  NA   
##  7 META  308.87 -1.45%   23.05M  NA   
##  8 Name  Last   Chg. %   Vol.    NA   
##  9 UNH   480.17 +7.24%   11.18M  NA   
## 10 ELV   438.73 +5.05%   2.50M   NA   
## # ℹ 13 more rows

1.3 Tìm hiểu 10 indicator của world bank

library(WDI)
## Warning: package 'WDI' was built under R version 4.3.1
citation("WDI")
## To cite package 'WDI' in publications use:
## 
##   Arel-Bundock V (2022). _WDI: World Development Indicators and Other
##   World Bank Data_. R package version 2.7.8,
##   <https://CRAN.R-project.org/package=WDI>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {WDI: World Development Indicators and Other World Bank Data},
##     author = {Vincent Arel-Bundock},
##     year = {2022},
##     note = {R package version 2.7.8},
##     url = {https://CRAN.R-project.org/package=WDI},
##   }
WDIsearch("GDP")
##                        indicator
## 712               5.51.01.10.gdp
## 714              6.0.GDP_current
## 715               6.0.GDP_growth
## 716                  6.0.GDP_usd
## 717           6.0.GDPpc_constant
## 1557           BG.GSR.NFSV.GD.ZS
## 1558        BG.KAC.FNEI.GD.PP.ZS
## 1559           BG.KAC.FNEI.GD.ZS
## 1560        BG.KLT.DINV.GD.PP.ZS
## 1561           BG.KLT.DINV.GD.ZS
## 1752           BI.WAG.TOTL.GD.ZS
## 1772              BM.GSR.MRCH.ZS
## 1784           BM.KLT.DINV.GD.ZS
## 1785        BM.KLT.DINV.WD.GD.ZS
## 1798           BN.CAB.XOKA.GD.ZS
## 1799          BN.CAB.XOKA.GDP.ZS
## 1802              BN.CAB.XOTR.ZS
## 1805              BN.CUR.GDPM.ZS
## 1811           BN.GSR.FCTY.CD.ZS
## 1820           BN.KLT.DINV.CD.ZS
## 1822      BN.KLT.DINV.DRS.GDP.ZS
## 1828           BN.KLT.PRVT.GD.ZS
## 1839           BN.TRF.CURR.CD.ZS
## 1875              BX.GSR.MRCH.ZS
## 1887        BX.KLT.DINV.DT.GD.ZS
## 1889        BX.KLT.DINV.WD.GD.ZS
## 1898         BX.TRF.MGR.DT.GD.ZS
## 1904        BX.TRF.PWKR.DT.GD.ZS
## 1905           BX.TRF.PWKR.GD.ZS
## 2198              CC.ENTX.ENE.ZS
## 2270              CC.GHG.MEMG.EI
## 2271              CC.GHG.MEMG.GC
## 2293                CC.INCP.ALRS
## 2294                CC.INCP.KRGC
## 2295                CC.INCP.SPMC
## 2356              CC.RISK.AST.ZS
## 2357             CC.RISK.WELL.ZS
## 2364                CC.SP.EXP.ZS
## 2401           CM.FIN.INTL.GD.ZS
## 2404           CM.MKT.LCAP.GD.ZS
## 2407           CM.MKT.TRAD.GD.ZS
## 2559        DP.DOD.DECD.CR.BC.Z1
## 2562        DP.DOD.DECD.CR.CG.Z1
## 2565        DP.DOD.DECD.CR.FC.Z1
## 2568        DP.DOD.DECD.CR.GG.Z1
## 2571        DP.DOD.DECD.CR.NF.Z1
## 2576        DP.DOD.DECF.CR.BC.Z1
## 2579        DP.DOD.DECF.CR.CG.Z1
## 2582        DP.DOD.DECF.CR.FC.Z1
## 2585        DP.DOD.DECF.CR.GG.Z1
## 2588        DP.DOD.DECF.CR.NF.Z1
## 2593        DP.DOD.DECN.CR.BC.Z1
## 2596        DP.DOD.DECN.CR.CG.Z1
## 2599        DP.DOD.DECN.CR.FC.Z1
## 2602        DP.DOD.DECN.CR.GG.Z1
## 2605        DP.DOD.DECN.CR.NF.Z1
## 2610        DP.DOD.DECT.CR.BC.Z1
## 2613        DP.DOD.DECT.CR.CG.Z1
## 2616        DP.DOD.DECT.CR.FC.Z1
## 2619        DP.DOD.DECT.CR.GG.Z1
## 2622        DP.DOD.DECT.CR.NF.Z1
## 2627        DP.DOD.DECX.CR.BC.Z1
## 2630        DP.DOD.DECX.CR.CG.Z1
## 2633        DP.DOD.DECX.CR.FC.Z1
## 2636        DP.DOD.DECX.CR.GG.Z1
## 2639        DP.DOD.DECX.CR.NF.Z1
## 2644        DP.DOD.DLCD.CR.BC.Z1
## 2647        DP.DOD.DLCD.CR.CG.Z1
## 2650        DP.DOD.DLCD.CR.FC.Z1
## 2653        DP.DOD.DLCD.CR.GG.Z1
## 2656     DP.DOD.DLCD.CR.L1.BC.Z1
## 2659     DP.DOD.DLCD.CR.L1.CG.Z1
## 2662     DP.DOD.DLCD.CR.L1.FC.Z1
## 2665     DP.DOD.DLCD.CR.L1.GG.Z1
## 2668     DP.DOD.DLCD.CR.L1.NF.Z1
## 2673     DP.DOD.DLCD.CR.M1.BC.Z1
## 2676     DP.DOD.DLCD.CR.M1.CG.Z1
## 2679     DP.DOD.DLCD.CR.M1.FC.Z1
## 2682     DP.DOD.DLCD.CR.M1.GG.Z1
## 2685     DP.DOD.DLCD.CR.M1.NF.Z1
## 2690        DP.DOD.DLCD.CR.NF.Z1
## 2694        DP.DOD.DLD1.CR.CG.Z1
## 2696        DP.DOD.DLD1.CR.GG.Z1
## 2698        DP.DOD.DLD2.CR.CG.Z1
## 2700        DP.DOD.DLD2.CR.GG.Z1
## 2702       DP.DOD.DLD2A.CR.CG.Z1
## 2704       DP.DOD.DLD2A.CR.GG.Z1
## 2706        DP.DOD.DLD3.CR.CG.Z1
## 2708        DP.DOD.DLD3.CR.GG.Z1
## 2710        DP.DOD.DLD4.CR.CG.Z1
## 2712        DP.DOD.DLD4.CR.GG.Z1
## 2715        DP.DOD.DLDS.CR.BC.Z1
## 2718        DP.DOD.DLDS.CR.CG.Z1
## 2721        DP.DOD.DLDS.CR.FC.Z1
## 2724        DP.DOD.DLDS.CR.GG.Z1
## 2727     DP.DOD.DLDS.CR.L1.BC.Z1
## 2730     DP.DOD.DLDS.CR.L1.CG.Z1
## 2733     DP.DOD.DLDS.CR.L1.FC.Z1
## 2736     DP.DOD.DLDS.CR.L1.GG.Z1
## 2739     DP.DOD.DLDS.CR.L1.NF.Z1
## 2744     DP.DOD.DLDS.CR.M1.BC.Z1
## 2747     DP.DOD.DLDS.CR.M1.CG.Z1
## 2750     DP.DOD.DLDS.CR.M1.FC.Z1
## 2753     DP.DOD.DLDS.CR.M1.GG.Z1
## 2756     DP.DOD.DLDS.CR.M1.NF.Z1
## 2761     DP.DOD.DLDS.CR.MV.BC.Z1
## 2764     DP.DOD.DLDS.CR.MV.CG.Z1
## 2767     DP.DOD.DLDS.CR.MV.FC.Z1
## 2770     DP.DOD.DLDS.CR.MV.GG.Z1
## 2773     DP.DOD.DLDS.CR.MV.NF.Z1
## 2778        DP.DOD.DLDS.CR.NF.Z1
## 2783        DP.DOD.DLIN.CR.BC.Z1
## 2786        DP.DOD.DLIN.CR.CG.Z1
## 2789        DP.DOD.DLIN.CR.FC.Z1
## 2792        DP.DOD.DLIN.CR.GG.Z1
## 2795     DP.DOD.DLIN.CR.L1.BC.Z1
## 2798     DP.DOD.DLIN.CR.L1.CG.Z1
## 2801     DP.DOD.DLIN.CR.L1.FC.Z1
## 2804     DP.DOD.DLIN.CR.L1.GG.Z1
## 2807     DP.DOD.DLIN.CR.L1.NF.Z1
## 2812     DP.DOD.DLIN.CR.M1.BC.Z1
## 2815     DP.DOD.DLIN.CR.M1.CG.Z1
## 2818     DP.DOD.DLIN.CR.M1.FC.Z1
## 2821     DP.DOD.DLIN.CR.M1.GG.Z1
## 2824     DP.DOD.DLIN.CR.M1.NF.Z1
## 2829        DP.DOD.DLIN.CR.NF.Z1
## 2834        DP.DOD.DLLO.CR.BC.Z1
## 2837        DP.DOD.DLLO.CR.CG.Z1
## 2840        DP.DOD.DLLO.CR.FC.Z1
## 2843        DP.DOD.DLLO.CR.GG.Z1
## 2846     DP.DOD.DLLO.CR.L1.BC.Z1
## 2849     DP.DOD.DLLO.CR.L1.CG.Z1
## 2852     DP.DOD.DLLO.CR.L1.FC.Z1
## 2855     DP.DOD.DLLO.CR.L1.GG.Z1
## 2858     DP.DOD.DLLO.CR.L1.NF.Z1
## 2863     DP.DOD.DLLO.CR.M1.BC.Z1
## 2866     DP.DOD.DLLO.CR.M1.CG.Z1
## 2869     DP.DOD.DLLO.CR.M1.FC.Z1
## 2872     DP.DOD.DLLO.CR.M1.GG.Z1
## 2875     DP.DOD.DLLO.CR.M1.NF.Z1
## 2880        DP.DOD.DLLO.CR.NF.Z1
## 2885        DP.DOD.DLOA.CR.BC.Z1
## 2888        DP.DOD.DLOA.CR.CG.Z1
## 2891        DP.DOD.DLOA.CR.FC.Z1
## 2894        DP.DOD.DLOA.CR.GG.Z1
## 2897     DP.DOD.DLOA.CR.L1.BC.Z1
## 2900     DP.DOD.DLOA.CR.L1.CG.Z1
## 2903     DP.DOD.DLOA.CR.L1.FC.Z1
## 2906     DP.DOD.DLOA.CR.L1.GG.Z1
## 2909     DP.DOD.DLOA.CR.L1.NF.Z1
## 2914     DP.DOD.DLOA.CR.M1.BC.Z1
## 2917     DP.DOD.DLOA.CR.M1.CG.Z1
## 2920     DP.DOD.DLOA.CR.M1.FC.Z1
## 2923     DP.DOD.DLOA.CR.M1.GG.Z1
## 2926     DP.DOD.DLOA.CR.M1.NF.Z1
## 2931        DP.DOD.DLOA.CR.NF.Z1
## 2936        DP.DOD.DLSD.CR.BC.Z1
## 2939        DP.DOD.DLSD.CR.CG.Z1
## 2942        DP.DOD.DLSD.CR.FC.Z1
## 2945        DP.DOD.DLSD.CR.GG.Z1
## 2948     DP.DOD.DLSD.CR.M1.BC.Z1
## 2951     DP.DOD.DLSD.CR.M1.CG.Z1
## 2954     DP.DOD.DLSD.CR.M1.FC.Z1
## 2957     DP.DOD.DLSD.CR.M1.GG.Z1
## 2960     DP.DOD.DLSD.CR.M1.NF.Z1
## 2965        DP.DOD.DLSD.CR.NF.Z1
## 2970        DP.DOD.DLTC.CR.BC.Z1
## 2973        DP.DOD.DLTC.CR.CG.Z1
## 2976        DP.DOD.DLTC.CR.FC.Z1
## 2979        DP.DOD.DLTC.CR.GG.Z1
## 2982     DP.DOD.DLTC.CR.L1.BC.Z1
## 2985     DP.DOD.DLTC.CR.L1.CG.Z1
## 2988     DP.DOD.DLTC.CR.L1.FC.Z1
## 2991     DP.DOD.DLTC.CR.L1.GG.Z1
## 2994     DP.DOD.DLTC.CR.L1.NF.Z1
## 2999     DP.DOD.DLTC.CR.M1.BC.Z1
## 3002     DP.DOD.DLTC.CR.M1.CG.Z1
## 3005     DP.DOD.DLTC.CR.M1.FC.Z1
## 3008     DP.DOD.DLTC.CR.M1.GG.Z1
## 3011     DP.DOD.DLTC.CR.M1.NF.Z1
## 3016        DP.DOD.DLTC.CR.NF.Z1
## 3022        DP.DOD.DSCD.CR.BC.Z1
## 3025        DP.DOD.DSCD.CR.CG.Z1
## 3028        DP.DOD.DSCD.CR.FC.Z1
## 3031        DP.DOD.DSCD.CR.GG.Z1
## 3034        DP.DOD.DSCD.CR.NF.Z1
## 3039        DP.DOD.DSDS.CR.BC.Z1
## 3042        DP.DOD.DSDS.CR.CG.Z1
## 3045        DP.DOD.DSDS.CR.FC.Z1
## 3048        DP.DOD.DSDS.CR.GG.Z1
## 3051        DP.DOD.DSDS.CR.NF.Z1
## 3056        DP.DOD.DSIN.CR.BC.Z1
## 3059        DP.DOD.DSIN.CR.CG.Z1
## 3062        DP.DOD.DSIN.CR.FC.Z1
## 3065        DP.DOD.DSIN.CR.GG.Z1
## 3068        DP.DOD.DSIN.CR.NF.Z1
## 3073        DP.DOD.DSLO.CR.BC.Z1
## 3076        DP.DOD.DSLO.CR.CG.Z1
## 3079        DP.DOD.DSLO.CR.FC.Z1
## 3082        DP.DOD.DSLO.CR.GG.Z1
## 3085        DP.DOD.DSLO.CR.NF.Z1
## 3090        DP.DOD.DSOA.CR.BC.Z1
## 3093        DP.DOD.DSOA.CR.CG.Z1
## 3096        DP.DOD.DSOA.CR.FC.Z1
## 3099        DP.DOD.DSOA.CR.GG.Z1
## 3102        DP.DOD.DSOA.CR.NF.Z1
## 3107        DP.DOD.DSTC.CR.BC.Z1
## 3110        DP.DOD.DSTC.CR.CG.Z1
## 3113        DP.DOD.DSTC.CR.FC.Z1
## 3116        DP.DOD.DSTC.CR.GG.Z1
## 3119        DP.DOD.DSTC.CR.NF.Z1
## 3615             DT.DOD.ALLC.ZSG
## 3618             DT.DOD.ALLN.ZSG
## 3773          DT.DOD.DECT.CD.ZSG
## 5376           DT.ODA.ALLD.GD.ZS
## 5447             DT.ODA.DACD.ZSG
## 5452             DT.ODA.MULT.ZSG
## 5460             DT.ODA.NDAC.ZSG
## 5466           DT.ODA.ODAT.GD.ZS
## 5616           DT.TDS.DECT.GD.ZS
## 5969           EG.EGY.PRIM.PP.KD
## 5993           EG.GDP.PUSE.KO.87
## 5994           EG.GDP.PUSE.KO.KD
## 5995           EG.GDP.PUSE.KO.PP
## 5996        EG.GDP.PUSE.KO.PP.KD
## 6004        EG.USE.COMM.GD.PP.KD
## 6023             EN.ATM.CO2E.GDP
## 6027        EN.ATM.CO2E.KD.87.GD
## 6028           EN.ATM.CO2E.KD.GD
## 6033           EN.ATM.CO2E.PP.GD
## 6034        EN.ATM.CO2E.PP.GD.KD
## 6164           ER.GDP.FWTL.M3.KD
## 6182             EU.EGY.USES.GDP
## 6236           FB.DPT.INSU.PC.ZS
## 6589           FD.AST.PRVT.GD.ZS
## 6595           FI.RES.TOTL.CD.ZS
## 7389           FM.AST.GOVT.CN.ZS
## 7398           FM.AST.PRVT.GD.ZS
## 7407           FM.LBL.BMNY.GD.ZS
## 7414           FM.LBL.MQMY.GD.ZS
## 7415          FM.LBL.MQMY.GDP.ZS
## 7417              FM.LBL.MQMY.XD
## 7422          FM.LBL.QMNY.GDP.ZS
## 7423          FM.LBL.SEIG.GDP.ZS
## 7462           FS.AST.CGOV.GD.ZS
## 7463           FS.AST.DOMO.GD.ZS
## 7464           FS.AST.DOMS.GD.ZS
## 7465              FS.AST.DTOT.ZS
## 7467           FS.AST.PRVT.GD.ZS
## 7468          FS.AST.PRVT.GDP.ZS
## 7469           FS.LBL.LIQU.GD.ZS
## 7470          FS.LBL.LIQU.GDP.ZS
## 7471           FS.LBL.QLIQ.GD.ZS
## 7530           GB.BAL.OVRL.GD.ZS
## 7531          GB.BAL.OVRL.GDP.ZS
## 7540           GB.DOD.TOTL.GD.ZS
## 7541          GB.DOD.TOTL.GDP.ZS
## 7545           GB.FIN.ABRD.GD.ZS
## 7546          GB.FIN.ABRD.GDP.ZS
## 7550           GB.FIN.DOMS.GD.ZS
## 7551          GB.FIN.DOMS.GDP.ZS
## 7561           GB.REV.CTOT.GD.ZS
## 7564          GB.REV.TOTL.GDP.ZS
## 7566           GB.REV.XAGT.CN.ZS
## 7569           GB.RVC.TOTL.GD.ZS
## 7571              GB.SOE.DECT.ZS
## 7573           GB.SOE.ECON.GD.ZS
## 7574          GB.SOE.ECON.GDP.ZS
## 7577           GB.SOE.NFLW.GD.ZS
## 7578          GB.SOE.NFLW.GDP.ZS
## 7579           GB.SOE.OVRL.GD.ZS
## 7605           GB.TAX.TOTL.GD.ZS
## 7606          GB.TAX.TOTL.GDP.ZS
## 7624          GB.XPD.DEFN.GDP.ZS
## 7627           GB.XPD.RSDV.GD.ZS
## 7630           GB.XPD.TOTL.GD.ZS
## 7631          GB.XPD.TOTL.GDP.ZS
## 7638           GC.AST.TOTL.GD.ZS
## 7641           GC.BAL.CASH.GD.ZS
## 7646           GC.DOD.TOTL.GD.ZS
## 7650           GC.FIN.DOMS.GD.ZS
## 7652           GC.FIN.FRGN.GD.ZS
## 7654           GC.LBL.TOTL.GD.ZS
## 7656           GC.NFN.TOTL.GD.ZS
## 7658           GC.NLD.TOTL.GD.ZS
## 7669           GC.REV.XGRT.GD.ZS
## 7684           GC.TAX.TOTL.GD.ZS
## 7701           GC.XPN.TOTL.GD.ZS
## 7792                  GFDD.DI.01
## 7793                  GFDD.DI.02
## 7794                  GFDD.DI.03
## 7796                  GFDD.DI.05
## 7797                  GFDD.DI.06
## 7798                  GFDD.DI.07
## 7799                  GFDD.DI.08
## 7800                  GFDD.DI.09
## 7801                  GFDD.DI.10
## 7802                  GFDD.DI.11
## 7803                  GFDD.DI.12
## 7804                  GFDD.DI.13
## 7805                  GFDD.DI.14
## 7806                  GFDD.DM.01
## 7807                  GFDD.DM.02
## 7808                  GFDD.DM.03
## 7809                  GFDD.DM.04
## 7810                  GFDD.DM.05
## 7811                  GFDD.DM.06
## 7812                  GFDD.DM.07
## 7813                  GFDD.DM.08
## 7814                  GFDD.DM.09
## 7815                  GFDD.DM.10
## 7816                  GFDD.DM.11
## 7817                  GFDD.DM.12
## 7818                  GFDD.DM.13
## 7821                  GFDD.DM.16
## 7822                  GFDD.DM.16
## 7830                  GFDD.EI.08
## 7837                  GFDD.OI.02
## 7843                  GFDD.OI.08
## 7844                  GFDD.OI.09
## 7848                  GFDD.OI.13
## 7849                  GFDD.OI.14
## 7854                  GFDD.OI.17
## 7855                  GFDD.OI.18
## 8686           IE.ICT.TOTL.GD.ZS
## 8959        IS.RRS.GOOD.KM.PP.ZS
## 8961        IS.RRS.PASG.K2.PP.ZS
## 9068           IT.TEL.REVN.GD.ZS
## 10943          MS.MIL.XPND.GD.ZS
## 10948     NA.GDP.ACC.FB.SNA08.CR
## 10949     NA.GDP.ACC.FB.SNA08.KR
## 10950              NA.GDP.AGR.CR
## 10951              NA.GDP.AGR.KR
## 10952        NA.GDP.AGR.SNA08.CR
## 10953        NA.GDP.AGR.SNA08.KR
## 10954       NA.GDP.BUSS.SNA08.CR
## 10955       NA.GDP.BUSS.SNA08.KR
## 10956             NA.GDP.CNST.CR
## 10957             NA.GDP.CNST.KR
## 10958       NA.GDP.CNST.SNA08.CR
## 10959       NA.GDP.CNST.SNA08.KR
## 10960       NA.GDP.EDUS.SNA08.CR
## 10961       NA.GDP.EDUS.SNA08.KR
## 10962   NA.GDP.ELEC.GAS.SNA08.CR
## 10963   NA.GDP.ELEC.GAS.SNA08.KR
## 10964           NA.GDP.EXC.OG.CR
## 10965           NA.GDP.EXC.OG.KR
## 10966             NA.GDP.FINS.CR
## 10967             NA.GDP.FINS.KR
## 10968       NA.GDP.FINS.SNA08.CR
## 10969       NA.GDP.FINS.SNA08.KR
## 10970  NA.GDP.HLTH.SOCW.SNA08.CR
## 10971  NA.GDP.HLTH.SOCW.SNA08.KR
## 10972           NA.GDP.INC.OG.CR
## 10973           NA.GDP.INC.OG.KR
## 10974     NA.GDP.INC.OG.SNA08.CR
## 10975     NA.GDP.INC.OG.SNA08.KR
## 10976   NA.GDP.INF.COMM.SNA08.CR
## 10977   NA.GDP.INF.COMM.SNA08.KR
## 10978             NA.GDP.MINQ.CR
## 10979             NA.GDP.MINQ.KR
## 10980       NA.GDP.MINQ.SNA08.CR
## 10981       NA.GDP.MINQ.SNA08.KR
## 10982              NA.GDP.MNF.CR
## 10983              NA.GDP.MNF.KR
## 10984        NA.GDP.MNF.SNA08.CR
## 10985        NA.GDP.MNF.SNA08.KR
## 10986   NA.GDP.PADM.DEF.SNA08.CR
## 10987   NA.GDP.PADM.DEF.SNA08.KR
## 10988       NA.GDP.REST.SNA08.CR
## 10989       NA.GDP.REST.SNA08.KR
## 10990         NA.GDP.SRV.OTHR.CR
## 10991         NA.GDP.SRV.OTHR.KR
## 10992   NA.GDP.SRV.OTHR.SNA08.CR
## 10993   NA.GDP.SRV.OTHR.SNA08.KR
## 10994        NA.GDP.TRAN.COMM.CR
## 10995        NA.GDP.TRAN.COMM.KR
## 10996  NA.GDP.TRAN.STOR.SNA08.CR
## 10997  NA.GDP.TRAN.STOR.SNA08.KR
## 10998          NA.GDP.TRD.HTL.CR
## 10999          NA.GDP.TRD.HTL.KR
## 11000        NA.GDP.TRD.SNA08.CR
## 11001        NA.GDP.TRD.SNA08.KR
## 11002              NA.GDP.UTL.CR
## 11003              NA.GDP.UTL.KR
## 11004    NA.GDP.WTR.WST.SNA08.CR
## 11005    NA.GDP.WTR.WST.SNA08.KR
## 11014             NE.CON.GOVT.ZS
## 11025             NE.CON.PETC.ZS
## 11042             NE.CON.PRVT.ZS
## 11052             NE.CON.TETC.ZS
## 11060             NE.CON.TOTL.ZG
## 11061             NE.CON.TOTL.ZS
## 11071             NE.DAB.TOTL.ZS
## 11083             NE.EXP.GNFS.ZS
## 11085         NE.GDI.CON.GOVT.CR
## 11086   NE.GDI.CON.GOVT.SNA08.CR
## 11087          NE.GDI.CON.NPI.CR
## 11088    NE.GDI.CON.NPI.SNA08.CR
## 11089         NE.GDI.CON.PRVT.CR
## 11090   NE.GDI.CON.PRVT.SNA08.CR
## 11091             NE.GDI.EXPT.CR
## 11092       NE.GDI.EXPT.SNA08.CR
## 11117             NE.GDI.FPRV.ZS
## 11122             NE.GDI.FPUB.ZS
## 11125             NE.GDI.FTOT.CR
## 11132       NE.GDI.FTOT.SNA08.CR
## 11133             NE.GDI.FTOT.ZS
## 11134             NE.GDI.IMPT.CR
## 11135       NE.GDI.IMPT.SNA08.CR
## 11136       NE.GDI.INEX.SNA08.CR
## 11141             NE.GDI.STKB.CR
## 11145       NE.GDI.STKB.SNA08.CR
## 11154             NE.GDI.TOTL.CR
## 11161       NE.GDI.TOTL.SNA08.CR
## 11162             NE.GDI.TOTL.ZG
## 11163             NE.GDI.TOTL.ZS
## 11173             NE.IMP.GNFS.ZS
## 11174             NE.MRCH.GDP.ZS
## 11180             NE.RSB.GNFS.ZG
## 11181             NE.RSB.GNFS.ZS
## 11184             NE.TRD.GNFS.ZS
## 11191             NP.AGR.TOTL.ZG
## 11195             NP.IND.TOTL.ZG
## 11201             NP.SRV.TOTL.ZG
## 11209          NV.AGR.PCAP.KD.ZG
## 11219             NV.AGR.TOTL.ZG
## 11220             NV.AGR.TOTL.ZS
## 11240             NV.IND.MANF.ZS
## 11254             NV.IND.TOTL.ZG
## 11255             NV.IND.TOTL.ZS
## 11273             NV.SRV.DISC.CD
## 11274             NV.SRV.DISC.CN
## 11275             NV.SRV.DISC.KN
## 11292             NV.SRV.TETC.ZG
## 11293             NV.SRV.TETC.ZS
## 11299             NV.SRV.TOTL.ZS
## 11388          NY.AGR.SUBS.GD.ZS
## 11392          NY.GDP.COAL.RT.ZS
## 11393          NY.GDP.DEFL.87.ZG
## 11394          NY.GDP.DEFL.KD.ZG
## 11395       NY.GDP.DEFL.KD.ZG.AD
## 11396             NY.GDP.DEFL.ZS
## 11397          NY.GDP.DEFL.ZS.87
## 11398          NY.GDP.DEFL.ZS.AD
## 11399             NY.GDP.DISC.CD
## 11400             NY.GDP.DISC.CN
## 11401             NY.GDP.DISC.KN
## 11405          NY.GDP.FCST.KD.87
## 11407          NY.GDP.FCST.KN.87
## 11408          NY.GDP.FRST.RT.ZS
## 11409          NY.GDP.MINR.RT.ZS
## 11410             NY.GDP.MKTP.CD
## 11411          NY.GDP.MKTP.CD.XD
## 11412             NY.GDP.MKTP.CN
## 11413          NY.GDP.MKTP.CN.AD
## 11414          NY.GDP.MKTP.CN.XD
## 11415             NY.GDP.MKTP.IN
## 11416             NY.GDP.MKTP.KD
## 11417          NY.GDP.MKTP.KD.87
## 11418          NY.GDP.MKTP.KD.ZG
## 11419             NY.GDP.MKTP.KN
## 11420          NY.GDP.MKTP.KN.87
## 11421       NY.GDP.MKTP.KN.87.ZG
## 11422          NY.GDP.MKTP.PP.CD
## 11423          NY.GDP.MKTP.PP.KD
## 11424       NY.GDP.MKTP.PP.KD.87
## 11425             NY.GDP.MKTP.XD
## 11426           NY.GDP.MKTP.XU.E
## 11428          NY.GDP.NGAS.RT.ZS
## 11429             NY.GDP.PCAP.CD
## 11430             NY.GDP.PCAP.CN
## 11431             NY.GDP.PCAP.KD
## 11432          NY.GDP.PCAP.KD.ZG
## 11433             NY.GDP.PCAP.KN
## 11434          NY.GDP.PCAP.PP.CD
## 11435          NY.GDP.PCAP.PP.KD
## 11436       NY.GDP.PCAP.PP.KD.87
## 11437       NY.GDP.PCAP.PP.KD.ZG
## 11438          NY.GDP.PETR.RT.ZS
## 11439          NY.GDP.TOTL.RT.ZS
## 11452             NY.GDS.TOTL.ZS
## 11457          NY.GEN.AEDU.GD.ZS
## 11458          NY.GEN.DCO2.GD.ZS
## 11459          NY.GEN.DFOR.GD.ZS
## 11460          NY.GEN.DKAP.GD.ZS
## 11461          NY.GEN.DMIN.GD.ZS
## 11462          NY.GEN.DNGY.GD.ZS
## 11463          NY.GEN.NDOM.GD.ZS
## 11464          NY.GEN.SVNG.GD.ZS
## 11497             NY.GNS.ICTR.ZS
## 11535               NYGDPMKTPKDZ
## 11536              NYGDPMKTPSACD
## 11537              NYGDPMKTPSACN
## 11538              NYGDPMKTPSAKD
## 11539              NYGDPMKTPSAKN
## 11564                 PA.NUS.PPP
## 11565              PA.NUS.PPP.05
## 11566             PA.NUS.PPPC.RF
## 15599              SE.PRM.SATT.2
## 15663              SE.PRM.TATT.1
## 15890             SE.XPD.EDUC.ZS
## 15895         SE.XPD.PRIM.GDP.ZS
## 15896          SE.XPD.PRIM.PC.ZS
## 15899         SE.XPD.SECO.GDP.ZS
## 15900          SE.XPD.SECO.PC.ZS
## 15904         SE.XPD.TERT.GDP.ZS
## 15905          SE.XPD.TERT.PC.ZS
## 15908          SE.XPD.TOTL.GD.ZS
## 15928          SF.TRN.RAIL.KM.ZS
## 16886          SH.XPD.CHEX.GD.ZS
## 16895          SH.XPD.GHED.GD.ZS
## 16899             SH.XPD.HLTH.ZS
## 16900          SH.XPD.KHEX.GD.ZS
## 16912             SH.XPD.PRIV.ZS
## 16915             SH.XPD.PUBL.ZS
## 16921             SH.XPD.TOTL.ZS
## 17073          SL.GDP.PCAP.EM.KD
## 17074       SL.GDP.PCAP.EM.KD.ZG
## 17075          SL.GDP.PCAP.EM.XD
## 17833       TG.VAL.TOTL.GD.PP.ZS
## 17834          TG.VAL.TOTL.GD.ZS
## 17835          TG.VAL.TOTL.GG.ZS
## 20066           UIS.XGDP.0.FSGOV
## 20067           UIS.XGDP.1.FSGOV
## 20068           UIS.XGDP.2.FSGOV
## 20069          UIS.XGDP.23.FSGOV
## 20070       UIS.XGDP.2T4.V.FSGOV
## 20071           UIS.XGDP.3.FSGOV
## 20072           UIS.XGDP.4.FSGOV
## 20073          UIS.XGDP.56.FSGOV
## 20123  UIS.XUNIT.GDPCAP.02.FSGOV
## 20124   UIS.XUNIT.GDPCAP.1.FSGOV
## 20125    UIS.XUNIT.GDPCAP.1.FSHH
## 20126   UIS.XUNIT.GDPCAP.2.FSGOV
## 20127  UIS.XUNIT.GDPCAP.23.FSGOV
## 20128   UIS.XUNIT.GDPCAP.23.FSHH
## 20129   UIS.XUNIT.GDPCAP.3.FSGOV
## 20130 UIS.XUNIT.GDPCAP.5T8.FSGOV
## 20131  UIS.XUNIT.GDPCAP.5T8.FSHH
##                                                                                                                                                                            name
## 712                                                                                                                                                       Per capita GDP growth
## 714                                                                                                                                                             GDP (current $)
## 715                                                                                                                                                       GDP growth (annual %)
## 716                                                                                                                                                       GDP (constant 2005 $)
## 717                                                                                                                        GDP per capita, PPP (constant 2011 international $) 
## 1557                                                                                                                                               Trade in services (% of GDP)
## 1558                                                                                                                                Gross private capital flows (% of GDP, PPP)
## 1559                                                                                                                                     Gross private capital flows (% of GDP)
## 1560                                                                                                                            Gross foreign direct investment (% of GDP, PPP)
## 1561                                                                                                                                 Gross foreign direct investment (% of GDP)
## 1752                                                                                                                                           Wage bill as a percentage of GDP
## 1772                                                                                                                           Merchandise imports (BOP): percentage of GDP (%)
## 1784                                                                                                                         Foreign direct investment, net outflows (% of GDP)
## 1785                                                                                                                         Foreign direct investment, net outflows (% of GDP)
## 1798                                                                                                                                         Current account balance (% of GDP)
## 1799                                                                                                                                         Current account balance (% of GDP)
## 1802                                                                                                                         Curr. acc. bal. before official transf. (% of GDP)
## 1805                                                                                                   Current account balance excluding net official capital grants (% of GDP)
## 1811                                                                                                                                                      Net income (% of GDP)
## 1820                                                                                                                                       Foreign direct investment (% of GDP)
## 1822                                                                                                                          Foreign direct investment, net inflows (% of GDP)
## 1828                                                                                                                                    Private capital flows, total (% of GDP)
## 1839                                                                                                                                           Net current transfers (% of GDP)
## 1875                                                                                                                           Merchandise exports (BOP): percentage of GDP (%)
## 1887                                                                                                                          Foreign direct investment, net inflows (% of GDP)
## 1889                                                                                                                          Foreign direct investment, net inflows (% of GDP)
## 1898                                                                                                                                      Migrant remittance inflows (% of GDP)
## 1904                                                                                                                                  Personal remittances, received (% of GDP)
## 1905                                                                                                                                  Workers' remittances, receipts (% of GDP)
## 2198                                                                                                                                        Total energy tax revenue (% of GDP)
## 2270                                                                                  Macro drivers of GHG emissions growth in the period 2012-2018 - Emission Intensity of GDP
## 2271                                                                                             Macro drivers of GHG emissions growth in the period 2012-2018 - GDP per capita
## 2293                                                                           Annual investment needs for coastal protection, by risk strategy (% of GDP) - low risk tolerance
## 2294                                                                 Annual investment needs for coastal protection, by risk strategy (% of GDP) - constant relative flood risk
## 2295                                                                           Annual investment needs for coastal protection, by risk strategy (% of GDP) - optimal protection
## 2356                                                                                                                          Risk to asset (average annual losses as % of GDP)
## 2357                                                                                                                      Risk to wellbeing (average annual losses as % of GDP)
## 2364                                                                                                                             Public social protection expenditure (%of GDP)
## 2401                                                                                                      Financing via international capital markets (gross inflows, % of GDP)
## 2404                                                                                                              Market capitalization of listed domestic companies (% of GDP)
## 2407                                                                                                                                      Stocks traded, total value (% of GDP)
## 2559                                                            Gross PSD, Budgetary Central Gov., All maturities, All instruments, Domestic creditors, Nominal Value, % of GDP
## 2562                                                                      Gross PSD, Central Gov., All maturities, All instruments, Domestic creditors, Nominal Value, % of GDP
## 2565                                                            Gross PSD, Financial Public Corp., All maturities, All instruments, Domestic creditors, Nominal Value, % of GDP
## 2568                                                                      Gross PSD, General Gov., All maturities, All instruments, Domestic creditors, Nominal Value, % of GDP
## 2571                                                         Gross PSD, Nonfinancial Public Corp., All maturities, All instruments, Domestic creditors, Nominal Value, % of GDP
## 2576                                                              Gross PSD, Budgetary Central Gov., All maturities, All instruments, Foreign currency, Nominal Value, % of GDP
## 2579                                                                        Gross PSD, Central Gov., All maturities, All instruments, Foreign currency, Nominal Value, % of GDP
## 2582                                                              Gross PSD, Financial Public Corp., All maturities, All instruments, Foreign currency, Nominal Value, % of GDP
## 2585                                                                        Gross PSD, General Gov., All maturities, All instruments, Foreign currency, Nominal Value, % of GDP
## 2588                                                           Gross PSD, Nonfinancial Public Corp., All maturities, All instruments, Foreign currency, Nominal Value, % of GDP
## 2593                                                             Gross PSD, Budgetary Central Gov., All maturities, All instruments, Domestic currency, Nominal Value, % of GDP
## 2596                                                                       Gross PSD, Central Gov., All maturities, All instruments, Domestic currency, Nominal Value, % of GDP
## 2599                                                             Gross PSD, Financial Public Corp., All maturities, All instruments, Domestic currency, Nominal Value, % of GDP
## 2602                                                                       Gross PSD, General Gov., All maturities, All instruments, Domestic currency, Nominal Value, % of GDP
## 2605                                                          Gross PSD, Nonfinancial Public Corp., All maturities, All instruments, Domestic currency, Nominal Value, % of GDP
## 2610                                                                                Gross PSD, Budgetary Central Gov., All maturities, All instruments, Nominal Value, % of GDP
## 2613                                                                                          Gross PSD, Central Gov., All maturities, All instruments, Nominal Value, % of GDP
## 2616                                                                                Gross PSD, Financial Public Corp., All maturities, All instruments, Nominal Value, % of GDP
## 2619                                                                                          Gross PSD, General Gov., All maturities, All instruments, Nominal Value, % of GDP
## 2622                                                                             Gross PSD, Nonfinancial Public Corp., All maturities, All instruments, Nominal Value, % of GDP
## 2627                                                            Gross PSD, Budgetary Central Gov., All maturities, All instruments, External creditors, Nominal Value, % of GDP
## 2630                                                                      Gross PSD, Central Gov., All maturities, All instruments, External creditors, Nominal Value, % of GDP
## 2633                                                            Gross PSD, Financial Public Corp., All maturities, All instruments, External creditors, Nominal Value, % of GDP
## 2636                                                                      Gross PSD, General Gov., All maturities, All instruments, External creditors, Nominal Value, % of GDP
## 2639                                                         Gross PSD, Nonfinancial Public Corp., All maturities, All instruments, External creditors, Nominal Value, % of GDP
## 2644                                                                          Gross PSD, Budgetary Central Gov., All maturities, Currency and deposits, Nominal Value, % of GDP
## 2647                                                                                    Gross PSD, Central Gov., All maturities, Currency and deposits, Nominal Value, % of GDP
## 2650                                                                          Gross PSD, Financial Public Corp., All maturities, Currency and deposits, Nominal Value, % of GDP
## 2653                                                                                    Gross PSD, General Gov., All maturities, Currency and deposits, Nominal Value, % of GDP
## 2656                                         Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, Currency and deposits, Nominal Value, % of GDP
## 2659                                                   Gross PSD, Central Gov., Long-term, With payment due in one year or less, Currency and deposits, Nominal Value, % of GDP
## 2662                                         Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, Currency and deposits, Nominal Value, % of GDP
## 2665                                                   Gross PSD, General Gov., Long-term, With payment due in one year or less, Currency and deposits, Nominal Value, % of GDP
## 2668                                      Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, Currency and deposits, Nominal Value, % of GDP
## 2673                                       Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Currency and deposits, Nominal Value, % of GDP
## 2676                                                 Gross PSD, Central Gov., Long-term, With payment due in more than one year, Currency and deposits, Nominal Value, % of GDP
## 2679                                       Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Currency and deposits, Nominal Value, % of GDP
## 2682                                                 Gross PSD, General Gov., Long-term, With payment due in more than one year, Currency and deposits, Nominal Value, % of GDP
## 2685                                    Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Currency and deposits, Nominal Value, % of GDP
## 2690                                                                       Gross PSD, Nonfinancial Public Corp., All maturities, Currency and deposits, Nominal Value, % of GDP
## 2694                                                                               Gross PSD, Central Gov.-D1, All maturities, Debt securities + loans, Nominal Value, % of GDP
## 2696                                                                               Gross PSD, General Gov.-D1, All maturities, Debt securities + loans, Nominal Value, % of GDP
## 2698                                                                      Gross PSD, Central Gov.-D2, All maturities, D1+ SDRs + currency and deposits, Nominal Value, % of GDP
## 2700                                                                      Gross PSD, General Gov.-D2, All maturities, D1+ SDRs + currency and deposits, Nominal Value, % of GDP
## 2702                                                                          Gross PSD, Central Gov.-D2A, All maturities, D1+ currency and deposits, Maastricht debt, % of GDP
## 2704                                                                          Gross PSD, General Gov.-D2A, All maturities, D1+ currency and deposits, Maastricht debt, % of GDP
## 2706                                                                             Gross PSD, Central Gov.-D3, All maturities, D2+other accounts payable, Nominal Value, % of GDP
## 2708                                                                             Gross PSD, General Gov.-D3, All maturities, D2+other accounts payable, Nominal Value, % of GDP
## 2710                                                   Gross PSD, Central Gov.-D4, All maturities, D3+insurance, pensions, and standardized guarantees, Nominal Value, % of GDP
## 2712                                                   Gross PSD, General Gov.-D4, All maturities, D3+insurance, pensions, and standardized guarantees, Nominal Value, % of GDP
## 2715                                                                                Gross PSD, Budgetary Central Gov., All maturities, Debt securities, Nominal Value, % of GDP
## 2718                                                                                          Gross PSD, Central Gov., All maturities, Debt securities, Nominal Value, % of GDP
## 2721                                                                                Gross PSD, Financial Public Corp., All maturities, Debt securities, Nominal Value, % of GDP
## 2724                                                                                          Gross PSD, General Gov., All maturities, Debt securities, Nominal Value, % of GDP
## 2727                                               Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, Debt securities, Nominal Value, % of GDP
## 2730                                                         Gross PSD, Central Gov., Long-term, With payment due in one year or less, Debt securities, Nominal Value, % of GDP
## 2733                                               Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, Debt securities, Nominal Value, % of GDP
## 2736                                                         Gross PSD, General Gov., Long-term, With payment due in one year or less, Debt securities, Nominal Value, % of GDP
## 2739                                            Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, Debt securities, Nominal Value, % of GDP
## 2744                                             Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Debt securities, Nominal Value, % of GDP
## 2747                                                       Gross PSD, Central Gov., Long-term, With payment due in more than one year, Debt securities, Nominal Value, % of GDP
## 2750                                             Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Debt securities, Nominal Value, % of GDP
## 2753                                                       Gross PSD, General Gov., Long-term, With payment due in more than one year, Debt securities, Nominal Value, % of GDP
## 2756                                          Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Debt securities, Nominal Value, % of GDP
## 2761                                                                                 Gross PSD, Budgetary Central Gov., All maturities, Debt Securities, Market value, % of GDP
## 2764                                                                                           Gross PSD, Central Gov., All maturities, Debt Securities, Market value, % of GDP
## 2767                                                                                 Gross PSD, Financial Public Corp., All maturities, Debt Securities, Market value, % of GDP
## 2770                                                                                           Gross PSD, General Gov., All maturities, Debt Securities, Market value, % of GDP
## 2773                                                                              Gross PSD, Nonfinancial Public Corp., All maturities, Debt Securities, Market value, % of GDP
## 2778                                                                             Gross PSD, Nonfinancial Public Corp., All maturities, Debt securities, Nominal Value, % of GDP
## 2783                                        Gross PSD, Budgetary Central Gov., All maturities, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2786                                                  Gross PSD, Central Gov., All maturities, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2789                                        Gross PSD, Financial Public Corp., All maturities, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2792                                                  Gross PSD, General Gov., All maturities, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2795       Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2798                 Gross PSD, Central Gov., Long-term, With payment due in one year or less, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2801       Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2804                 Gross PSD, General Gov., Long-term, With payment due in one year or less, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2807    Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2812     Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2815               Gross PSD, Central Gov., Long-term, With payment due in more than one year, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2818     Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2821               Gross PSD, General Gov., Long-term, With payment due in more than one year, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2824  Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2829                                     Gross PSD, Nonfinancial Public Corp., All maturities, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 2834                                                                                          Gross PSD, Budgetary Central Gov., All maturities, Loans, Nominal Value, % of GDP
## 2837                                                                                                    Gross PSD, Central Gov., All maturities, Loans, Nominal Value, % of GDP
## 2840                                                                                          Gross PSD, Financial Public Corp., All maturities, Loans, Nominal Value, % of GDP
## 2843                                                                                                    Gross PSD, General Gov., All maturities, Loans, Nominal Value, % of GDP
## 2846                                                         Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, Loans, Nominal Value, % of GDP
## 2849                                                                   Gross PSD, Central Gov., Long-term, With payment due in one year or less, Loans, Nominal Value, % of GDP
## 2852                                                         Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, Loans, Nominal Value, % of GDP
## 2855                                                                   Gross PSD, General Gov., Long-term, With payment due in one year or less, Loans, Nominal Value, % of GDP
## 2858                                                      Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, Loans, Nominal Value, % of GDP
## 2863                                                       Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Loans, Nominal Value, % of GDP
## 2866                                                                 Gross PSD, Central Gov., Long-term, With payment due in more than one year, Loans, Nominal Value, % of GDP
## 2869                                                       Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Loans, Nominal Value, % of GDP
## 2872                                                                 Gross PSD, General Gov., Long-term, With payment due in more than one year, Loans, Nominal Value, % of GDP
## 2875                                                    Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Loans, Nominal Value, % of GDP
## 2880                                                                                       Gross PSD, Nonfinancial Public Corp., All maturities, Loans, Nominal Value, % of GDP
## 2885                                                                         Gross PSD, Budgetary Central Gov., All maturities, Other accounts payable, Nominal Value, % of GDP
## 2888                                                                                   Gross PSD, Central Gov., All maturities, Other accounts payable, Nominal Value, % of GDP
## 2891                                                                         Gross PSD, Financial Public Corp., All maturities, Other accounts payable, Nominal Value, % of GDP
## 2894                                                                                   Gross PSD, General Gov., All maturities, Other accounts payable, Nominal Value, % of GDP
## 2897                                        Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, Other accounts payable, Nominal Value, % of GDP
## 2900                                                  Gross PSD, Central Gov., Long-term, With payment due in one year or less, Other accounts payable, Nominal Value, % of GDP
## 2903                                        Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, Other accounts payable, Nominal Value, % of GDP
## 2906                                                  Gross PSD, General Gov., Long-term, With payment due in one year or less, Other accounts payable, Nominal Value, % of GDP
## 2909                                     Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, Other accounts payable, Nominal Value, % of GDP
## 2914                                      Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Other accounts payable, Nominal Value, % of GDP
## 2917                                                Gross PSD, Central Gov., Long-term, With payment due in more than one year, Other accounts payable, Nominal Value, % of GDP
## 2920                                      Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Other accounts payable, Nominal Value, % of GDP
## 2923                                                Gross PSD, General Gov., Long-term, With payment due in more than one year, Other accounts payable, Nominal Value, % of GDP
## 2926                                   Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Other accounts payable, Nominal Value, % of GDP
## 2931                                                                      Gross PSD, Nonfinancial Public Corp., All maturities, Other accounts payable, Nominal Value, % of GDP
## 2936                                                                         Gross PSD, Budgetary Central Gov., All maturities, Special Drawing Rights, Nominal Value, % of GDP
## 2939                                                                                   Gross PSD, Central Gov., All maturities, Special Drawing Rights, Nominal Value, % of GDP
## 2942                                                                         Gross PSD, Financial Public Corp., All maturities, Special Drawing Rights, Nominal Value, % of GDP
## 2945                                                                                   Gross PSD, General Gov., All maturities, Special Drawing Rights, Nominal Value, % of GDP
## 2948                                      Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, Special Drawing Rights, Nominal Value, % of GDP
## 2951                                                Gross PSD, Central Gov., Long-term, With payment due in more than one year, Special Drawing Rights, Nominal Value, % of GDP
## 2954                                      Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, Special Drawing Rights, Nominal Value, % of GDP
## 2957                                                Gross PSD, General Gov., Long-term, With payment due in more than one year, Special Drawing Rights, Nominal Value, % of GDP
## 2960                                   Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, Special Drawing Rights, Nominal Value, % of GDP
## 2965                                                                      Gross PSD, Nonfinancial Public Corp., All maturities, Special Drawing Rights, Nominal Value, % of GDP
## 2970                                                                                     Gross PSD, Budgetary Central Gov., Long-term, All instruments, Nominal Value, % of GDP
## 2973                                                                                               Gross PSD, Central Gov., Long-term, All instruments, Nominal Value, % of GDP
## 2976                                                                                     Gross PSD, Financial Public Corp., Long-term, All instruments, Nominal Value, % of GDP
## 2979                                                                                               Gross PSD, General Gov., Long-term, All instruments, Nominal Value, % of GDP
## 2982                                               Gross PSD, Budgetary Central Gov., Long-term, With payment due in one year or less, All instruments, Nominal Value, % of GDP
## 2985                                                         Gross PSD, Central Gov., Long-term, With payment due in one year or less, All instruments, Nominal Value, % of GDP
## 2988                                               Gross PSD, Financial Public Corp., Long-term, With payment due in one year or less, All instruments, Nominal Value, % of GDP
## 2991                                                         Gross PSD, General Gov., Long-term, With payment due in one year or less, All instruments, Nominal Value, % of GDP
## 2994                                            Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in one year or less, All instruments, Nominal Value, % of GDP
## 2999                                             Gross PSD, Budgetary Central Gov., Long-term, With payment due in more than one year, All instruments, Nominal Value, % of GDP
## 3002                                                       Gross PSD, Central Gov., Long-term, With payment due in more than one year, All instruments, Nominal Value, % of GDP
## 3005                                             Gross PSD, Financial Public Corp., Long-term, With payment due in more than one year, All instruments, Nominal Value, % of GDP
## 3008                                                       Gross PSD, General Gov., Long-term, With payment due in more than one year, All instruments, Nominal Value, % of GDP
## 3011                                          Gross PSD, Nonfinancial Public Corp., Long-term, With payment due in more than one year, All instruments, Nominal Value, % of GDP
## 3016                                                                                  Gross PSD, Nonfinancial Public Corp., Long-term, All instruments, Nominal Value, % of GDP
## 3022                                                                              Gross PSD, Budgetary Central Gov., Short-term, Currency and deposits, Nominal Value, % of GDP
## 3025                                                                                        Gross PSD, Central Gov., Short-term, Currency and deposits, Nominal Value, % of GDP
## 3028                                                                              Gross PSD, Financial Public Corp., Short-term, Currency and deposits, Nominal Value, % of GDP
## 3031                                                                                        Gross PSD, General Gov., Short-term, Currency and deposits, Nominal Value, % of GDP
## 3034                                                                           Gross PSD, Nonfinancial Public Corp., Short-term, Currency and deposits, Nominal Value, % of GDP
## 3039                                                                                    Gross PSD, Budgetary Central Gov., Short-term, Debt securities, Nominal Value, % of GDP
## 3042                                                                                              Gross PSD, Central Gov., Short-term, Debt securities, Nominal Value, % of GDP
## 3045                                                                                    Gross PSD, Financial Public Corp., Short-term, Debt securities, Nominal Value, % of GDP
## 3048                                                                                              Gross PSD, General Gov., Short-term, Debt securities, Nominal Value, % of GDP
## 3051                                                                                 Gross PSD, Nonfinancial Public Corp., Short-term, Debt securities, Nominal Value, % of GDP
## 3056                                            Gross PSD, Budgetary Central Gov., Short-term, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 3059                                                      Gross PSD, Central Gov., Short-term, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 3062                                            Gross PSD, Financial Public Corp., Short-term, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 3065                                                      Gross PSD, General Gov., Short-term, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 3068                                         Gross PSD, Nonfinancial Public Corp., Short-term, Insurance, pensions, and standardized guarantee schemes, Nominal Value, % of GDP
## 3073                                                                                              Gross PSD, Budgetary Central Gov., Short-term, Loans, Nominal Value, % of GDP
## 3076                                                                                                        Gross PSD, Central Gov., Short-term, Loans, Nominal Value, % of GDP
## 3079                                                                                              Gross PSD, Financial Public Corp., Short-term, Loans, Nominal Value, % of GDP
## 3082                                                                                                        Gross PSD, General Gov., Short-term, Loans, Nominal Value, % of GDP
## 3085                                                                                           Gross PSD, Nonfinancial Public Corp., Short-term, Loans, Nominal Value, % of GDP
## 3090                                                                             Gross PSD, Budgetary Central Gov., Short-term, Other accounts payable, Nominal Value, % of GDP
## 3093                                                                                       Gross PSD, Central Gov., Short-term, Other accounts payable, Nominal Value, % of GDP
## 3096                                                                             Gross PSD, Financial Public Corp., Short-term, Other accounts payable, Nominal Value, % of GDP
## 3099                                                                                       Gross PSD, General Gov., Short-term, Other accounts payable, Nominal Value, % of GDP
## 3102                                                                          Gross PSD, Nonfinancial Public Corp., Short-term, Other accounts payable, Nominal Value, % of GDP
## 3107                                                                                    Gross PSD, Budgetary Central Gov., Short-term, All instruments, Nominal Value, % of GDP
## 3110                                                                                              Gross PSD, Central Gov., Short-term, All instruments, Nominal Value, % of GDP
## 3113                                                                                    Gross PSD, Financial Public Corp., Short-term, All instruments, Nominal Value, % of GDP
## 3116                                                                                              Gross PSD, General Gov., Short-term, All instruments, Nominal Value, % of GDP
## 3119                                                                                 Gross PSD, Nonfinancial Public Corp., Short-term, All instruments, Nominal Value, % of GDP
## 3615                                                                                                                               Debt on Concessional terms to GDP (% of GDP)
## 3618                                                                                                                           Debt on Non-concessional terms to GDP (% of GDP)
## 3773                                                                                                                    Debt outstanding and disbursed, Total to GDP (% of GDP)
## 5376                                                                                                                                                Net ODA received (% of GDP)
## 5447                                                                                                                    Net ODA received from DAC donors (% of recipient's GDP)
## 5452                                                                                                                       Net ODA received from multilateral donors (% of GDP)
## 5460                                                                                                                  Net ODA received from non-DAC bilateral donors (% of GDP)
## 5466                                                                                                                                                Net ODA received (% of GDP)
## 5616                                                                                                                                              Total debt service (% of GDP)
## 5969                                                                                                                Energy intensity level of primary energy (MJ/$2017 PPP GDP)
## 5993                                                                                                             GDP per unit of energy use (1987 US$ per kg of oil equivalent)
## 5994                                                                                                             GDP per unit of energy use (2000 US$ per kg of oil equivalent)
## 5995                                                                                                                GDP per unit of energy use (PPP $ per kg of oil equivalent)
## 5996                                                                                                  GDP per unit of energy use (constant 2017 PPP $ per kg of oil equivalent)
## 6004                                                                                                       Energy use (kg of oil equivalent) per $1,000 GDP (constant 2017 PPP)
## 6023                                                                                                                         CO2 emissions, industrial (kg per 1987 US$ of GDP)
## 6027                                                                                                                         CO2 emissions, industrial (kg per 1987 US$ of GDP)
## 6028                                                                                                                                     CO2 emissions (kg per 2015 US$ of GDP)
## 6033                                                                                                                                        CO2 emissions (kg per PPP $ of GDP)
## 6034                                                                                                                                   CO2 emissions (kg per 2017 PPP $ of GDP)
## 6164                                                                           Water productivity, total (constant 2015 US$ GDP per cubic meter of total freshwater withdrawal)
## 6182                                                                                                             GDP per unit of energy use (1987 US$ per kg of oil equivalent)
## 6236                                                                                                                           Deposit insurance coverage (% of GDP per capita)
## 6589                                                                                                                      Domestic credit to private sector by banks (% of GDP)
## 6595                                                                                                                                    Total reserves includes gold (% of GDP)
## 7389                                                                                                                 Claims on governments and other public entities (% of GDP)
## 7398                                                                                                                           Monetary Sector credit to private sector (% GDP)
## 7407                                                                                                                                                     Broad money (% of GDP)
## 7414                                                                                                                                     Money and quasi money (M2) as % of GDP
## 7415                                                                                                                                     Money and quasi money (M2) as % of GDP
## 7417                                                                                                                                          Income velocity of money (GDP/M2)
## 7422                                                                                                                                        Quasi-liquid liabilities (% of GDP)
## 7423                                                                                                                                                      Seignorage (% of GDP)
## 7462                                                                                                                                 Claims on central government, etc. (% GDP)
## 7463                                                                                                                 Claims on other sectors of the domestic economy (% of GDP)
## 7464                                                                                                                    Domestic credit provided by financial sector (% of GDP)
## 7465                                                                                                                      Domestic credit provided by banking sector (% of GDP)
## 7467                                                                                                                               Domestic credit to private sector (% of GDP)
## 7468                                                                                                                                        Credit to private sector (% of GDP)
## 7469                                                                                                                                        Liquid liabilities (M3) as % of GDP
## 7470                                                                                                                                        Liquid liabilities (M3) as % of GDP
## 7471                                                                                                                                        Quasi-liquid liabilities (% of GDP)
## 7530                                                                                                                        Overall budget balance, including grants (% of GDP)
## 7531                                                                                                                        Overall budget deficit, including grants (% of GDP)
## 7540                                                                                                                                  Central government debt, total (% of GDP)
## 7541                                                                                                                                  Central government debt, total (% of GDP)
## 7545                                                                                                                                           Financing from abroad (% of GDP)
## 7546                                                                                                                                           Financing from abroad (% of GDP)
## 7550                                                                                                                                       Domestic financing, total (% of GDP)
## 7551                                                                                                                                             Domestic finanacing (% of GDP)
## 7561                                                                                                                               Current revenue, excluding grants (% of GDP)
## 7564                                                                                                                                                 Current revenue (% of GDP)
## 7566                                                                                                               Central government revenues, excluding all grants (% of GDP)
## 7569                                                                                                                               Current revenue, excluding grants (% of GDP)
## 7571                                                                                                                                               SOE external debt (% of GDP)
## 7573                                                                                                                      State-owned enterprises, economic activity (% of GDP)
## 7574                                                                                                                                           SOE economic activity (% of GDP)
## 7577                                                                                                    State-owned enterprises, net financial flows from government (% of GDP)
## 7578                                                                                                                         SOE net financial flows from government (% of GDP)
## 7579                                                                                                       State-owned enterprises, overall balance before transfers (% of GDP)
## 7605                                                                                                                                                     Tax revenue (% of GDP)
## 7606                                                                                                                                                     Tax revenue (% of GDP)
## 7624                                                                                                                                             Defense expenditure (% of GDP)
## 7627                                                                                                                            Research and development expenditure (% of GDP)
## 7630                                                                                                                                              Expenditure, total (% of GDP)
## 7631                                                                                                                                               Total expenditure (% of GDP)
## 7638                                                                                                                             Net acquisition of financial assets (% of GDP)
## 7641                                                                                                                                            Cash surplus/deficit (% of GDP)
## 7646                                                                                                                                  Central government debt, total (% of GDP)
## 7650                                                                                                                         Net incurrence of liabilities, domestic (% of GDP)
## 7652                                                                                                                          Net incurrence of liabilities, foreign (% of GDP)
## 7654                                                                                                                            Net incurrence of liabilities, total (% of GDP)
## 7656                                                                                                                           Net investment in nonfinancial assets (% of GDP)
## 7658                                                                                                                             Net lending (+) / net borrowing (-) (% of GDP)
## 7669                                                                                                                                       Revenue, excluding grants (% of GDP)
## 7684                                                                                                                                                     Tax revenue (% of GDP)
## 7701                                                                                                                                                         Expense (% of GDP)
## 7792                                                                                                                           Private credit by deposit money banks to GDP (%)
## 7793                                                                                                                                    Deposit money banks'' assets to GDP (%)
## 7794                                                                                                                          Nonbank financial institutions’ assets to GDP (%)
## 7796                                                                                                                                              Liquid liabilities to GDP (%)
## 7797                                                                                                                                             Central bank assets to GDP (%)
## 7798                                                                                                                                              Mutual fund assets to GDP (%)
## 7799                                                                                                                                       Financial system deposits to GDP (%)
## 7800                                                                                                                                   Life insurance premium volume to GDP (%)
## 7801                                                                                                                               Non-life insurance premium volume to GDP (%)
## 7802                                                                                                                                        Insurance company assets to GDP (%)
## 7803                                                                                          Private credit by deposit money banks and other financial institutions to GDP (%)
## 7804                                                                                                                                             Pension fund assets to GDP (%)
## 7805                                                                                                                               Domestic credit to private sector (% of GDP)
## 7806                                                                                                                                     Stock market capitalization to GDP (%)
## 7807                                                                                                                                 Stock market total value traded to GDP (%)
## 7808                                                                                                                    Outstanding domestic private debt securities to GDP (%)
## 7809                                                                                                                     Outstanding domestic public debt securities to GDP (%)
## 7810                                                                                                               Outstanding international private debt securities to GDP (%)
## 7811                                                                                                                Outstanding international public debt securities to GDP (%)
## 7812                                                                                                                                       International debt issues to GDP (%)
## 7813                                                                                                                              Gross portfolio equity liabilities to GDP (%)
## 7814                                                                                                                                   Gross portfolio equity assets to GDP (%)
## 7815                                                                                                                                Gross portfolio debt liabilities to GDP (%)
## 7816                                                                                                                                     Gross portfolio debt assets to GDP (%)
## 7817                                                                                                                                 Syndicated loan issuance volume to GDP (%)
## 7818                                                                                                                                  Corporate bond issuance volume to GDP (%)
## 7821                                                                                                                   Credit flows by fintech and bigtech companies to GDP (%)
## 7822                                                                                                                   Credit flows by fintech and bigtech companies to GDP (%)
## 7830                                                                                                                Credit to government and state-owned enterprises to GDP (%)
## 7837                                                                                                                                                   Bank deposits to GDP (%)
## 7843                                                                                                                              Loans from nonresident banks (net) to GDP (%)
## 7844                                                                                                              Loans from nonresident banks (amounts outstanding) to GDP (%)
## 7848                                                                                                                                              Remittance inflows to GDP (%)
## 7849                                                                                                              Consolidated foreign claims of BIS reporting banks to GDP (%)
## 7854                                                                                                                                           Global leasing volume to GDP (%)
## 7855                                                                                                                                          Total factoring volume to GDP (%)
## 8686                                                                                                            Information and communication technology expenditure (% of GDP)
## 8959                                                                                                              Railways, goods transported (ton-km per PPP $ million of GDP)
## 8961                                                                                                                          Railways, passenger-km (per PPP $ million of GDP)
## 9068                                                                                                                                         Telecommunications revenue (% GDP)
## 10943                                                                                                                                           Military expenditure (% of GDP)
## 10948                                                                           GDP on Accommodation & Food Beverages Activity Sector (in IDR Million), SNA 2008, Current Price
## 10949                                                                          GDP on Accommodation & Food Beverages Activity Sector (in IDR Million), SNA 2008, Constant Price
## 10950                                                                                                                 GDP on Agriculture Sector (in IDR Million), Current Price
## 10951                                                                                                                GDP on Agriculture Sector (in IDR Million), Constant Price
## 10952                                                                                 GDP on Agriculture, Forestry & Fisheries Sector (in IDR Million), SNA 2008, Current Price
## 10953                                                                                GDP on Agriculture, Forestry & Fisheries Sector (in IDR Million), SNA 2008, Constant Price
## 10954                                                                                                 GDP on Business Services Sector (in IDR Million), SNA 2008, Current Price
## 10955                                                                                                GDP on Business Services Sector (in IDR Million), SNA 2008, Constant Price
## 10956                                                                                                                GDP on Construction Sector (in IDR Million), Current Price
## 10957                                                                                                               GDP on Construction Sector (in IDR Million), Constant Price
## 10958                                                                                                      GDP on Construction Sector (in IDR Million), SNA 2008, Current Price
## 10959                                                                                                     GDP on Construction Sector (in IDR Million), SNA 2008, Constant Price
## 10960                                                                                                GDP on Education Services Sector (in IDR Million), SNA 2008, Current Price
## 10961                                                                                               GDP on Education Services Sector (in IDR Million), SNA 2008, Constant Price
## 10962                                                                                          GDP on Electricity & Gas Supply Sector (in IDR Million), SNA 2008, Current Price
## 10963                                                                                         GDP on Electricity & Gas Supply Sector (in IDR Million), SNA 2008, Constant Price
## 10964                                                                                                           Total GDP excluding Oil and Gas (in IDR Million), Current Price
## 10965                                                                                                          Total GDP excluding Oil and Gas (in IDR Million), Constant Price
## 10966                                                                                                           GDP on Financial Service Sector (in IDR Million), Current Price
## 10967                                                                                                          GDP on Financial Service Sector (in IDR Million), Constant Price
## 10968                                                                                    GDP on Financial & Insurance Activity Sector (in IDR Million), SNA 2008, Current Price
## 10969                                                                                   GDP on Financial & Insurance Activity Sector (in IDR Million), SNA 2008, Constant Price
## 10970                                                                               GDP on Human Health & Social Work Activity Sector (in IDR Million), SNA 2008, Current Price
## 10971                                                                              GDP on Human Health & Social Work Activity Sector (in IDR Million), SNA 2008, Constant Price
## 10972                                                                                                           Total GDP including Oil and Gas (in IDR Million), Current Price
## 10973                                                                                                          Total GDP including Oil and Gas (in IDR Million), Constant Price
## 10974                                                                                                 Total GDP including Oil and Gas (in IDR Million), SNA 2008, Current Price
## 10975                                                                                                Total GDP including Oil and Gas (in IDR Million), SNA 2008, Constant Price
## 10976                                                                                       GDP on Information & Communication Sector (in IDR Million), SNA 2008, Current Price
## 10977                                                                                      GDP on Information & Communication Sector (in IDR Million), SNA 2008, Constant Price
## 10978                                                                                                        GDP on Mining and Quarrying Sector (in IDR Million), Current Price
## 10979                                                                                                       GDP on Mining and Quarrying Sector (in IDR Million), Constant Price
## 10980                                                                                                GDP on Mining & Quarrying Sector (in IDR Million), SNA 2008, Current Price
## 10981                                                                                               GDP on Mining & Quarrying Sector (in IDR Million), SNA 2008, Constant Price
## 10982                                                                                                               GDP on Manufacturing Sector (in IDR Million), Current Price
## 10983                                                                                                              GDP on Manufacturing Sector (in IDR Million), Constant Price
## 10984                                                                                            GDP on Manufacturing Industry Sector (in IDR Million), SNA 2008, Current Price
## 10985                                                                                           GDP on Manufacturing Industry Sector (in IDR Million), SNA 2008, Constant Price
## 10986                                                       GDP on Public Administration, Defense & Compulsory Social Security Sector (in IDR Million), SNA 2008, Current Price
## 10987                                                      GDP on Public Administration, Defense & Compulsory Social Security Sector (in IDR Million), SNA 2008, Constant Price
## 10988                                                                                                       GDP on Real Estate Sector (in IDR Million), SNA 2008, Current Price
## 10989                                                                                                      GDP on Real Estate Sector (in IDR Million), SNA 2008, Constant Price
## 10990                                                                                                               GDP on Other Service Sector (in IDR Million), Current Price
## 10991                                                                                                              GDP on Other Service Sector (in IDR Million), Constant Price
## 10992                                                                                                    GDP on Other Services Sector (in IDR Million), SNA 2008, Current Price
## 10993                                                                                                   GDP on Other Services Sector (in IDR Million), SNA 2008, Constant Price
## 10994                                                                                        GDP on Transportation and Telecommunication Sector (in IDR Million), Current Price
## 10995                                                                                       GDP on Transportation and Telecommunication Sector (in IDR Million), Constant Price
## 10996                                                                                          GDP on Transportation & Storage Sector (in IDR Million), SNA 2008, Current Price
## 10997                                                                                         GDP on Transportation & Storage Sector (in IDR Million), SNA 2008, Constant Price
## 10998                                                                                                 GDP on Trade, Hotel and Restaurant Sector (in IDR Million), Current Price
## 10999                                                                                                GDP on Trade, Hotel and Restaurant Sector (in IDR Million), Constant Price
## 11000                                                 GDP on Wholesales & Retail Trade, Repair of Motor Vehicles & Motorcycles Sector (in IDR Million), SNA 2008, Current Price
## 11001                                                GDP on Wholesales & Retail Trade, Repair of Motor Vehicles & Motorcycles Sector (in IDR Million), SNA 2008, Constant Price
## 11002                                                                                                                   GDP on Utilities Sector (in IDR Million), Current Price
## 11003                                                                                                                  GDP on Utilities Sector (in IDR Million), Constant Price
## 11004                                                              GDP on Water Supply, Sewerage, Waste & Recycling Management Sector (in IDR Million), SNA 2008, Current Price
## 11005                                                             GDP on Water Supply, Sewerage, Waste & Recycling Management Sector (in IDR Million), SNA 2008, Constant Price
## 11014                                                                                                               General government final consumption expenditure (% of GDP)
## 11025                                                                                                                  Household final consumption expenditure, etc. (% of GDP)
## 11042                                                                                                            Households and NPISHs final consumption expenditure (% of GDP)
## 11052                                                                                                                            Final consumption expenditure, etc. (% of GDP)
## 11060                                                                                                                      Total consumption: contribution to growth of GDP (%)
## 11061                                                                                                                                  Final consumption expenditure (% of GDP)
## 11071                                                                                                                                     Gross national expenditure (% of GDP)
## 11083                                                                                                                                  Exports of goods and services (% of GDP)
## 11085                                                                                                        GDP expenditure on general government consumption (in IDR Million)
## 11086                                                                               GDP expenditure on general government consumption (in IDR Million), SNA 2008, Current Price
## 11087                                                                                            GDP expenditure on non profit private institution consumption (in IDR Million)
## 11088                                                                   GDP expenditure on non profit private institution consumption (in IDR Million), SNA 2008, Current Price
## 11089                                                                                                                   GDP expenditure on private consumption (in IDR Million)
## 11090                                                                                          GDP expenditure on private consumption (in IDR Million), SNA 2008, Current Price
## 11091                                                                                                                               GDP expenditure on exports (in IDR Million)
## 11092                                                                                                      GDP expenditure on exports (in IDR Million), SNA 2008, Current Price
## 11117                                                                                                                  Gross fixed capital formation, private sector (% of GDP)
## 11122                                                                                                                                        Gross public investment (% of GDP)
## 11125                                                                                                         GDP expenditure on gross fixed capital formation (in IDR Million)
## 11132                                                                                GDP expenditure on gross fixed capital formation (in IDR Million), SNA 2008, Current Price
## 11133                                                                                                                                  Gross fixed capital formation (% of GDP)
## 11134                                                                                                                               GDP expenditure on imports (in IDR Million)
## 11135                                                                                                      GDP expenditure on imports (in IDR Million), SNA 2008, Current Price
## 11136                                                                                     GDP expenditure on inter-region net exports (in IDR Million), SNA 2008, Current Price
## 11141                                                                                                                      GDP expenditure on changes in stock (in IDR Million)
## 11145                                                                                             GDP expenditure on changes in stock (in IDR Million), SNA 2008, Current Price
## 11154                                                                                                                           Total GDP based on expenditure (in IDR Million)
## 11161                                                                                                  Total GDP based on expenditure (in IDR Million), SNA 2008, Current Price
## 11162                                                                                                                     Gross domestic investment: contr. to growth of GDP(%)
## 11163                                                                                                                                        Gross capital formation (% of GDP)
## 11173                                                                                                                                  Imports of goods and services (% of GDP)
## 11174                                                                                                                                        Merchandise trade to GDP ratio (%)
## 11180                                                                                                                       Resource balance: contribution to growth of GDP (%)
## 11181                                                                                                                         External balance on goods and services (% of GDP)
## 11184                                                                                                                                                          Trade (% of GDP)
## 11191                                                                                                                            Agriculture: contribution to growth of GDP (%)
## 11195                                                                                                                               Industry: contribution to growth of GDP (%)
## 11201                                                                                                                               Services: contribution to growth of GDP (%)
## 11209                                                                                                                          Real agricultural GDP per capita growth rate (%)
## 11219                                                                                                                                    Real agricultural GDP growth rates (%)
## 11220                                                                                                                Agriculture, forestry, and fishing, value added (% of GDP)
## 11240                                                                                                                                     Manufacturing, value added (% of GDP)
## 11254                                                                                                                               Industry: contribution to growth of GDP (%)
## 11255                                                                                                                 Industry (including construction), value added (% of GDP)
## 11273                                                                                                                             Discrepancy in GDP, value added (current US$)
## 11274                                                                                                                             Discrepancy in GDP, value added (current LCU)
## 11275                                                                                                                            Discrepancy in GDP, value added (constant LCU)
## 11292                                                                                                                               Services: contribution to growth of GDP (%)
## 11293                                                                                                                                    Services, etc., value added (% of GDP)
## 11299                                                                                                                                          Services, value added (% of GDP)
## 11388                                                                                                                                  Agricultural support estimate (% of GDP)
## 11392                                                                                                                                                     Coal rents (% of GDP)
## 11393                                                                                                                                        Inflation, GDP deflator (annual %)
## 11394                                                                                                                                        Inflation, GDP deflator (annual %)
## 11395                                                                                                                         Inflation, GDP deflator: linked series (annual %)
## 11396                                                                                                                                GDP deflator (base year varies by country)
## 11397                                                                                                                                                 GDP deflator (1987 = 100)
## 11398                                                                                                                 GDP deflator: linked series (base year varies by country)
## 11399                                                                                                                  Discrepancy in expenditure estimate of GDP (current US$)
## 11400                                                                                                                  Discrepancy in expenditure estimate of GDP (current LCU)
## 11401                                                                                                                 Discrepancy in expenditure estimate of GDP (constant LCU)
## 11405                                                                                                                                    GDP at factor cost (constant 1987 US$)
## 11407                                                                                                                                    GDP at factor cost (constant 1987 LCU)
## 11408                                                                                                                                                   Forest rents (% of GDP)
## 11409                                                                                                                                                  Mineral rents (% of GDP)
## 11410                                                                                                                                                         GDP (current US$)
## 11411                                                                                                                                GDP deflator, index (2000=100; US$ series)
## 11412                                                                                                                                                         GDP (current LCU)
## 11413                                                                                                                                          GDP: linked series (current LCU)
## 11414                                                                                                                         GDP deflator, period average (LCU index 2000=100)
## 11415                                                                                                                                                              GDP Deflator
## 11416                                                                                                                                                   GDP (constant 2015 US$)
## 11417                                                                                                                                  GDP at market prices (constant 1987 US$)
## 11418                                                                                                                                                     GDP growth (annual %)
## 11419                                                                                                                                                        GDP (constant LCU)
## 11420                                                                                                                                  GDP at market prices (constant 1987 LCU)
## 11421                                                                                                                                                     GDP growth (annual %)
## 11422                                                                                                                                        GDP, PPP (current international $)
## 11423                                                                                                                                  GDP, PPP (constant 2017 international $)
## 11424                                                                                                                                  GDP, PPP (constant 1987 international $)
## 11425                                                                                                                                             GDP deflator (1987=100,Index)
## 11426                                                                                                                    GDP deflator, end period (base year varies by country)
## 11428                                                                                                                                              Natural gas rents (% of GDP)
## 11429                                                                                                                                              GDP per capita (current US$)
## 11430                                                                                                                                              GDP per capita (current LCU)
## 11431                                                                                                                                        GDP per capita (constant 2015 US$)
## 11432                                                                                                                                          GDP per capita growth (annual %)
## 11433                                                                                                                                             GDP per capita (constant LCU)
## 11434                                                                                                                             GDP per capita, PPP (current international $)
## 11435                                                                                                                       GDP per capita, PPP (constant 2017 international $)
## 11436                                                                                                                       GDP per capita, PPP (constant 1987 international $)
## 11437                                                                                                                                     GDP per capita, PPP annual growth (%)
## 11438                                                                                                                                                      Oil rents (% of GDP)
## 11439                                                                                                                                  Total natural resources rents (% of GDP)
## 11452                                                                                                                                         Gross domestic savings (% of GDP)
## 11457                                                                                                                         Genuine savings: education expenditure (% of GDP)
## 11458                                                                                                                         Genuine savings: carbon dioxide damage (% of GDP)
## 11459                                                                                                                          Genuine savings: net forest depletion (% of GDP)
## 11460                                                                                                                  Genuine savings: consumption of fixed capital (% of GDP)
## 11461                                                                                                                             Genuine savings: mineral depletion (% of GDP)
## 11462                                                                                                                              Genuine savings: energy depletion (% of GDP)
## 11463                                                                                                                          Genuine savings: net domestic savings (% of GDP)
## 11464                                                                                                                                       Genuine domestic savings (% of GDP)
## 11497                                                                                                                                                  Gross savings (% of GDP)
## 11535                                                                                  Annual percentage growth rate of GDP at market prices based on constant 2010 US Dollars.
## 11536                                                                                                                                      GDP,current US$,millions,seas. adj.,
## 11537                                                                                                                                      GDP,current LCU,millions,seas. adj.,
## 11538                                                                                                                                GDP,constant 2010 US$,millions,seas. adj.,
## 11539                                                                                                                                GDP,constant 2010 LCU,millions,seas. adj.,
## 11564                                                                                                                      PPP conversion factor, GDP (LCU per international $)
## 11565                                                                                                                 2005 PPP conversion factor, GDP (LCU per international $)
## 11566                                                                                                  Price level ratio of PPP conversion factor (GDP) to market exchange rate
## 15599                                                                                                          (De Facto) Average principal salary as percent of GDP per capita
## 15663                                                                                      (De Jure) Average starting public-school teacher salary as percent of GDP per capita
## 15890                                                                                                                                  Public Expenditure on Education  (% GDP)
## 15895                                                                                                                          Public spending on education, primary (% of GDP)
## 15896                                                                                                         Government expenditure per student, primary (% of GDP per capita)
## 15899                                                                                                                        Public spending on education, secondary (% of GDP)
## 15900                                                                                                       Government expenditure per student, secondary (% of GDP per capita)
## 15904                                                                                                                         Public spending on education, tertiary (% of GDP)
## 15905                                                                                                        Government expenditure per student, tertiary (% of GDP per capita)
## 15908                                                                                                                     Government expenditure on education, total (% of GDP)
## 15928                                                                                                                                     Rail traffic (km per million US$ GDP)
## 16886                                                                                                                                     Current health expenditure (% of GDP)
## 16895                                                                                                                 Domestic general government health expenditure (% of GDP)
## 16899                                                                                                                                      Public Expenditure on Health (% GDP)
## 16900                                                                                                                                     Capital health expenditure (% of GDP)
## 16912                                                                                                                                    Health expenditure, private (% of GDP)
## 16915                                                                                                                                     Health expenditure, public (% of GDP)
## 16921                                                                                                                                      Health expenditure, total (% of GDP)
## 17073                                                                                                                             GDP per person employed (constant 2017 PPP $)
## 17074                                                                                                                                 GDP per person employed (annual % growth)
## 17075                                                                                                                               GDP per person employed, index (1980 = 100)
## 17833                                                                                                                                                     Trade (% of GDP, PPP)
## 17834                                                                                                                                              Merchandise trade (% of GDP)
## 17835                                                                                                                                           Trade in goods (% of goods GDP)
## 20066                                                                                                           Government expenditure on pre-primary education as % of GDP (%)
## 20067                                                                                                               Government expenditure on primary education as % of GDP (%)
## 20068                                                                                            Government expenditure on lower secondary education as a percentage of GDP (%)
## 20069                                                                                                             Government expenditure on secondary education as % of GDP (%)
## 20070                                                                  Government expenditure on secondary and post-secondary non-tertiary vocational education as % of GDP (%)
## 20071                                                                                            Government expenditure on upper secondary education as a percentage of GDP (%)
## 20072                                                                                           Government expenditure on post-secondary non-tertiary education as % of GDP (%)
## 20073                                                                                                              Government expenditure on tertiary education as % of GDP (%)
## 20123                                                                                      Initial government funding per pre-primary student as a percentage of GDP per capita
## 20124                                                                                          Initial government funding per primary student as a percentage of GDP per capita
## 20125                                                                                           Initial household funding per primary student as a percentage of GDP per capita
## 20126                                                                                  Initial government funding per lower secondary student as a percentage of GDP per capita
## 20127                                                                                        Initial government funding per secondary student as a percentage of GDP per capita
## 20128                                                                                         Initial household funding per secondary student as a percentage of GDP per capita
## 20129                                                                                  Initial government funding per upper secondary student as a percentage of GDP per capita
## 20130                                                                                         Initial government funding per tertiary student as a percentage of GDP per capita
## 20131                                                                                          Initial household funding per tertiary student as a percentage of GDP per capita
WDIsearch("GDP.*growth")
##                  indicator                                             name
## 712         5.51.01.10.gdp                            Per capita GDP growth
## 715         6.0.GDP_growth                            GDP growth (annual %)
## 11209    NV.AGR.PCAP.KD.ZG Real agricultural GDP per capita growth rate (%)
## 11219       NV.AGR.TOTL.ZG           Real agricultural GDP growth rates (%)
## 11418    NY.GDP.MKTP.KD.ZG                            GDP growth (annual %)
## 11421 NY.GDP.MKTP.KN.87.ZG                            GDP growth (annual %)
## 11432    NY.GDP.PCAP.KD.ZG                 GDP per capita growth (annual %)
## 11437 NY.GDP.PCAP.PP.KD.ZG            GDP per capita, PPP annual growth (%)
## 17074 SL.GDP.PCAP.EM.KD.ZG        GDP per person employed (annual % growth)

2 Bài thực hành tuần 5+6

2.1 Mô tả dữ liệu

Ở tuần này, em sẽ tổng quát lại các thao tác em đã thực hiện trên toàn bộ dữ liệu Journals.

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.1
## Warning: package 'ggplot2' was built under R version 4.3.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.4
## ✔ ggplot2   3.4.2     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()         masks stats::filter()
## ✖ readr::guess_encoding() masks rvest::guess_encoding()
## ✖ dplyr::lag()            masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(DT)
## Warning: package 'DT' was built under R version 4.3.1
library(Ecdat)
## Warning: package 'Ecdat' was built under R version 4.3.1
## Loading required package: Ecfun
## Warning: package 'Ecfun' was built under R version 4.3.1
## 
## Attaching package: 'Ecfun'
## 
## The following object is masked from 'package:base':
## 
##     sign
## 
## 
## Attaching package: 'Ecdat'
## 
## The following object is masked from 'package:datasets':
## 
##     Orange
library(ggplot2)
library(scales)
## Warning: package 'scales' was built under R version 4.3.1
## 
## Attaching package: 'scales'
## 
## The following object is masked from 'package:purrr':
## 
##     discard
## 
## The following object is masked from 'package:readr':
## 
##     col_factor
library(utf8)
## Warning: package 'utf8' was built under R version 4.3.1
data(Journals)
d <- Journals
str(d)
## 'data.frame':    180 obs. of  10 variables:
##  $ title   : Factor w/ 179 levels "Agricultural Economics",..: 8 174 18 144 130 137 48 168 42 143 ...
##  $ pub     : Factor w/ 52 levels "Academic Press",..: 11 45 28 28 18 18 13 18 28 11 ...
##  $ society : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ libprice: int  123 20 443 276 295 344 90 242 226 262 ...
##  $ pages   : int  440 309 567 520 791 609 602 665 243 386 ...
##  $ charpp  : int  3822 1782 2924 3234 3024 2967 3185 2688 3010 2501 ...
##  $ citestot: int  21 22 22 22 24 24 24 27 28 30 ...
##  $ date1   : int  1986 1986 1987 1991 1972 1994 1995 1968 1987 1949 ...
##  $ oclc    : int  14 59 17 2 96 15 14 202 46 46 ...
##  $ field   : Factor w/ 24 levels "Ag Econ","Area Studies",..: 10 7 22 2 14 16 6 22 2 10 ...
names(d) <- c('T','PU','SO','PR','PA','CH','CI','F','SU','FI')
datatable(d, options = list( sscrollX= TRUE))

Đọc 6 dòng đầu tiên của dữ liệu và 6 dòng cuối của dữ liệu

head(d)
##                                                     T                     PU SO
## 1                   Asian-Pacific Economic Literature              Blackwell no
## 2           South African Journal of Economic History So Afr ec history assn no
## 3                             Computational Economics                 Kluwer no
## 4 MOCT-MOST Economic Policy in Transitional Economics                 Kluwer no
## 5                          Journal of Socio-Economics               Elsevier no
## 6                                    Labour Economics               Elsevier no
##    PR  PA   CH CI    F SU                FI
## 1 123 440 3822 21 1986 14           General
## 2  20 309 1782 22 1986 59        Ec History
## 3 443 567 2924 22 1987 17       Specialized
## 4 276 520 3234 22 1991  2      Area Studies
## 5 295 791 3024 24 1972 96 Interdisciplinary
## 6 344 609 2967 24 1994 15             Labor
tail(d)
##                                        T                    PU  SO  PR   PA
## 175 Journal of American Statistical Assn  Am. Statistical Assn yes 310 1260
## 176                   Journal of Finance      Am. Finance Assn yes 226 2272
## 177       Quarterly Journal of Economics             MIT press  no 148 1467
## 178         Journal of Political Economy Univ of Chicago Press  no 159 1669
## 179                         Econometrica             Blackwell yes 178 1482
## 180             American Economic Review            Am Ec Assn yes  47 1867
##       CH   CI    F   SU           FI
## 175 5664 2800 1971  487 Econometrics
## 176 3036 3791 1945  799      Finance
## 177 2184 4138 1886  660      General
## 178 2640 6697 1892  737      General
## 179 2992 7943 1932  346      General
## 180 3900 8999 1911 1098      General

2.2 Hàm summary

Trong phần này đầu tiên, em thực hiện câu lệnh summary() để tóm tắt thống kê.

summary(d$PR)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    20.0   134.5   282.0   417.7   540.8  2120.0

Qua khảo sát cho thấy giá sách bán tại Hoa Kì năm 2020 có giá thấp nhất là 20 usd và cao nhất là 2120 usd .Trung bình giá sách có giá khoảng 417,7 usd

summary(d$SU)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     2.0    52.0   122.5   196.9   268.2  1098.0

Kết quả khảo sát cho thấy số lượng đăng kí sách tại thư viện ít nhất là 2 người , nhiều nhất là 1098 người, trung bình có khoảng 197 người đăng kí

summary(d$SO)
##  no yes 
## 164  16

Có 16 tạp chí được sản xuất bởi một xa hội học thuật và có 164 tạp chí không được sản xuất bởi xã hội học thuật

2.3 Hàm sum() , var()

sum(d$PR)
## [1] 75190

Tổng số tiền thư viện bán được tạp chí là 75190 usd trong năm 2020 tại Hoa Kì

sum(d$SU)
## [1] 35436

Tổng số lượng đăng kí tạp chí tại hoa kì năm 2020 là 35436 người

sum(d$PA)
## [1] 148994

Tổng số trang trong tạp chí là 148994 trang

var(d$PR)
## [1] 148868.3
var(d$PA)
## [1] 190809.4
var(d$SU)
## [1] 41832.05

148868.3 đại diện cho mức giá bán tạp chí của thư viện , 190809.4 đại diện cho số trang của tạp chí, 41832.05 đại diện cho số lượng đăng kí mua tạp chí của thư viện.

2.4 Hàm aggregate

aggregate(d$PR,list(d$SO),FUN ='mean')
##   Group.1        x
## 1      no 435.4695
## 2     yes 235.8125
aggregate(d$PR,list(d$SO),FUN ='max')
##   Group.1    x
## 1      no 2120
## 2     yes 1154
aggregate(d$PR,list(d$SO),FUN ='var')
##   Group.1        x
## 1      no 148920.7
## 2     yes 119483.2
aggregate(d$PR,list(d$SO),FUN ='sd')
##   Group.1        x
## 1      no 385.9024
## 2     yes 345.6635

2.5 Xoay trục dữ liệu

library(tidyr)
library(tidyverse)

2.6 Dùng lệnh Longer_Pivot để trình bày lại dữ liệu từ hàng thành cột (rút gọn bộ dữ liệu)

Ta dùng hàm pivot_longer() trong package tidyverse để làm “dài” dữ liệu , tăng số lượng hàng và giảm số lượng cột.

Đầu tiên , ta gọi package tidyverse xuất hiện.

Tiếp theo , sử dụng hàm pivot_longer() để gom các cột đã nêu ở trên (tương ứng với các cột có thứ tự từ 6 đến 10) thành 2 cột mới . Một cột có tên là ‘religion’ , chứa tên các yếu tố làm ảnh hưởng đến các giới tính (tên các cột cũ) và một cột tên ‘age’ , chứa các giá trị tương ứng.

relig_income
## # A tibble: 18 × 11
##    religion `<$10k` `$10-20k` `$20-30k` `$30-40k` `$40-50k` `$50-75k` `$75-100k`
##    <chr>      <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>      <dbl>
##  1 Agnostic      27        34        60        81        76       137        122
##  2 Atheist       12        27        37        52        35        70         73
##  3 Buddhist      27        21        30        34        33        58         62
##  4 Catholic     418       617       732       670       638      1116        949
##  5 Don’t k…      15        14        15        11        10        35         21
##  6 Evangel…     575       869      1064       982       881      1486        949
##  7 Hindu          1         9         7         9        11        34         47
##  8 Histori…     228       244       236       238       197       223        131
##  9 Jehovah…      20        27        24        24        21        30         15
## 10 Jewish        19        19        25        25        30        95         69
## 11 Mainlin…     289       495       619       655       651      1107        939
## 12 Mormon        29        40        48        51        56       112         85
## 13 Muslim         6         7         9        10         9        23         16
## 14 Orthodox      13        17        23        32        32        47         38
## 15 Other C…       9         7        11        13        13        14         18
## 16 Other F…      20        33        40        46        49        63         46
## 17 Other W…       5         2         3         4         2         7          3
## 18 Unaffil…     217       299       374       365       341       528        407
## # ℹ 3 more variables: `$100-150k` <dbl>, `>150k` <dbl>,
## #   `Don't know/refused` <dbl>
relig_income %>%
 pivot_longer(-religion, 
              names_to = "income", 
              values_to = "count")
## # A tibble: 180 × 3
##    religion income             count
##    <chr>    <chr>              <dbl>
##  1 Agnostic <$10k                 27
##  2 Agnostic $10-20k               34
##  3 Agnostic $20-30k               60
##  4 Agnostic $30-40k               81
##  5 Agnostic $40-50k               76
##  6 Agnostic $50-75k              137
##  7 Agnostic $75-100k             122
##  8 Agnostic $100-150k            109
##  9 Agnostic >150k                 84
## 10 Agnostic Don't know/refused    96
## # ℹ 170 more rows
who %>% pivot_longer(
  cols = new_sp_m014:newrel_f65,
  names_to = c("diagnosis", "gender", "age"),
  names_pattern = "new_?(.*)_(.)(.*)",
  values_to = "count"
)
## # A tibble: 405,440 × 8
##    country     iso2  iso3   year diagnosis gender age   count
##    <chr>       <chr> <chr> <dbl> <chr>     <chr>  <chr> <dbl>
##  1 Afghanistan AF    AFG    1980 sp        m      014      NA
##  2 Afghanistan AF    AFG    1980 sp        m      1524     NA
##  3 Afghanistan AF    AFG    1980 sp        m      2534     NA
##  4 Afghanistan AF    AFG    1980 sp        m      3544     NA
##  5 Afghanistan AF    AFG    1980 sp        m      4554     NA
##  6 Afghanistan AF    AFG    1980 sp        m      5564     NA
##  7 Afghanistan AF    AFG    1980 sp        m      65       NA
##  8 Afghanistan AF    AFG    1980 sp        f      014      NA
##  9 Afghanistan AF    AFG    1980 sp        f      1524     NA
## 10 Afghanistan AF    AFG    1980 sp        f      2534     NA
## # ℹ 405,430 more rows
anscombe
##    x1 x2 x3 x4    y1   y2    y3    y4
## 1  10 10 10  8  8.04 9.14  7.46  6.58
## 2   8  8  8  8  6.95 8.14  6.77  5.76
## 3  13 13 13  8  7.58 8.74 12.74  7.71
## 4   9  9  9  8  8.81 8.77  7.11  8.84
## 5  11 11 11  8  8.33 9.26  7.81  8.47
## 6  14 14 14  8  9.96 8.10  8.84  7.04
## 7   6  6  6  8  7.24 6.13  6.08  5.25
## 8   4  4  4 19  4.26 3.10  5.39 12.50
## 9  12 12 12  8 10.84 9.13  8.15  5.56
## 10  7  7  7  8  4.82 7.26  6.42  7.91
## 11  5  5  5  8  5.68 4.74  5.73  6.89
anscombe %>%
 pivot_longer(everything(),
   names_to = c(".value", "set"),
   names_pattern = "(.)(.)"
 )
## # A tibble: 44 × 3
##    set       x     y
##    <chr> <dbl> <dbl>
##  1 1        10  8.04
##  2 2        10  9.14
##  3 3        10  7.46
##  4 4         8  6.58
##  5 1         8  6.95
##  6 2         8  8.14
##  7 3         8  6.77
##  8 4         8  5.76
##  9 1        13  7.58
## 10 2        13  8.74
## # ℹ 34 more rows

2.7 Dùng lệnh Longer_wider để trình bày lại dữ liệu từ cột thành hàng

Trong một số trường hợp , ta muốn chuyển đổi bộ dữ liệu sang định dạng ngang thì ta có thể sử dụng hàm pivot_wider() , tăng số lượng cột và giảm số lượng dòng.

head(tidyr::fish_encounters)
## # A tibble: 6 × 3
##   fish  station  seen
##   <fct> <fct>   <int>
## 1 4842  Release     1
## 2 4842  I80_1       1
## 3 4842  Lisbon      1
## 4 4842  Rstr        1
## 5 4842  Base_TD     1
## 6 4842  BCE         1
tidyr::fish_encounters %>%
  pivot_wider(names_from = station, 
              values_from = seen)
## # A tibble: 19 × 12
##    fish  Release I80_1 Lisbon  Rstr Base_TD   BCE   BCW  BCE2  BCW2   MAE   MAW
##    <fct>   <int> <int>  <int> <int>   <int> <int> <int> <int> <int> <int> <int>
##  1 4842        1     1      1     1       1     1     1     1     1     1     1
##  2 4843        1     1      1     1       1     1     1     1     1     1     1
##  3 4844        1     1      1     1       1     1     1     1     1     1     1
##  4 4845        1     1      1     1       1    NA    NA    NA    NA    NA    NA
##  5 4847        1     1      1    NA      NA    NA    NA    NA    NA    NA    NA
##  6 4848        1     1      1     1      NA    NA    NA    NA    NA    NA    NA
##  7 4849        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
##  8 4850        1     1     NA     1       1     1     1    NA    NA    NA    NA
##  9 4851        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 10 4854        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 11 4855        1     1      1     1       1    NA    NA    NA    NA    NA    NA
## 12 4857        1     1      1     1       1     1     1     1     1    NA    NA
## 13 4858        1     1      1     1       1     1     1     1     1     1     1
## 14 4859        1     1      1     1       1    NA    NA    NA    NA    NA    NA
## 15 4861        1     1      1     1       1     1     1     1     1     1     1
## 16 4862        1     1      1     1       1     1     1     1     1    NA    NA
## 17 4863        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 18 4864        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 19 4865        1     1      1    NA      NA    NA    NA    NA    NA    NA    NA
fish_encounters %>%
  pivot_wider(
    names_from = station,
    values_from = seen,
    values_fill = list(seen = 0)
  )
## # A tibble: 19 × 12
##    fish  Release I80_1 Lisbon  Rstr Base_TD   BCE   BCW  BCE2  BCW2   MAE   MAW
##    <fct>   <int> <int>  <int> <int>   <int> <int> <int> <int> <int> <int> <int>
##  1 4842        1     1      1     1       1     1     1     1     1     1     1
##  2 4843        1     1      1     1       1     1     1     1     1     1     1
##  3 4844        1     1      1     1       1     1     1     1     1     1     1
##  4 4845        1     1      1     1       1     0     0     0     0     0     0
##  5 4847        1     1      1     0       0     0     0     0     0     0     0
##  6 4848        1     1      1     1       0     0     0     0     0     0     0
##  7 4849        1     1      0     0       0     0     0     0     0     0     0
##  8 4850        1     1      0     1       1     1     1     0     0     0     0
##  9 4851        1     1      0     0       0     0     0     0     0     0     0
## 10 4854        1     1      0     0       0     0     0     0     0     0     0
## 11 4855        1     1      1     1       1     0     0     0     0     0     0
## 12 4857        1     1      1     1       1     1     1     1     1     0     0
## 13 4858        1     1      1     1       1     1     1     1     1     1     1
## 14 4859        1     1      1     1       1     0     0     0     0     0     0
## 15 4861        1     1      1     1       1     1     1     1     1     1     1
## 16 4862        1     1      1     1       1     1     1     1     1     0     0
## 17 4863        1     1      0     0       0     0     0     0     0     0     0
## 18 4864        1     1      0     0       0     0     0     0     0     0     0
## 19 4865        1     1      1     0       0     0     0     0     0     0     0
head(tidyr::us_rent_income)
## # A tibble: 6 × 5
##   GEOID NAME    variable estimate   moe
##   <chr> <chr>   <chr>       <dbl> <dbl>
## 1 01    Alabama income      24476   136
## 2 01    Alabama rent          747     3
## 3 02    Alaska  income      32940   508
## 4 02    Alaska  rent         1200    13
## 5 04    Arizona income      27517   148
## 6 04    Arizona rent          972     4
warpbreaks <- as_tibble(warpbreaks[c("wool", "tension", "breaks")])
head(warpbreaks, 10)
## # A tibble: 10 × 3
##    wool  tension breaks
##    <fct> <fct>    <dbl>
##  1 A     L           26
##  2 A     L           30
##  3 A     L           54
##  4 A     L           25
##  5 A     L           70
##  6 A     L           52
##  7 A     L           51
##  8 A     L           26
##  9 A     L           67
## 10 A     M           18
warpbreaks %>%
  pivot_wider(
    names_from = wool,
    values_from = breaks,
    values_fn = list(breaks = mean)
  )
## # A tibble: 3 × 3
##   tension     A     B
##   <fct>   <dbl> <dbl>
## 1 L        44.6  28.2
## 2 M        24    28.8
## 3 H        24.6  18.8

2.8 Biểu đồ hình tròn [ dùng pie()]

Sử dụng biến subs (số lượng đăng kí thư viện) để vẽ biểu đồ tròn dựa trên 5 nhóm phân loại đánh giá về số lượng đăng kí của người được khảo sát.

# phân 5 nhóm cho biến subs 
table(cut(d$SU,5))
## 
##   (0.904,221]     (221,440]     (440,660]     (660,879] (879,1.1e+03] 
##           124            32            17             5             2
# vẽ biểu đồ dựa trên 5 nhóm đã phân loại 
pie(table(cut(d$SU,5)))

. Màu trắng là nhóm giá trị từ khoảng 0,904 đến bằng 221

. Màu xanh lam là nhóm giá trị từ khoảng 221 đến bằng 440

. Màu hồng là nhóm giá trị từ khoảng 440 đến bằng 660

. Màu xanh mint là nhóm giá trị từ khoảng 660 đến bằng 879

. Màu tím là nhóm giá trị từ khoảng 879 đến bằng 1.1e + 03

2.9 Đồ thị phân phối xác xuất bằng hàm plot(density)

Đồ thị mật độ phân phối xác suất cho biến “Price” bằng hàm density()

plot(density(d$PR),add=TRUE)
## Warning in plot.window(...): "add" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "add" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter

## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in box(...): "add" is not a graphical parameter
## Warning in title(...): "add" is not a graphical parameter

Từ đồ thị cho thấy, phân phối của biến “price” giá sách từ 200 đến 500 là cao nhất và từ 500 đến 2500 trở đi phân phối ngày càng giảm dần. Điều đó có nghĩa là giá được khảo sát ở khoảng trung bình từ 200-500

2.10 Đồ thị dạng scatter

Biểu đồ phân tán (scatter plot):

Sử dụng các dấu chấm để thể hiện giá trị (điểm giao nhau) của hai biến số khác nhau.

Dùng để quan sát mối tương quan giữa 2 biến định lượng.

Trục hoành (trục X) mô tả biến độc lập. Trục tung (Y) mô tả biến phụ thuộc.

ggplot(data=iris, mapping = aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point()

2.11 Đồ thị cột

Biểu đồ cột mô tả các nhóm trong một biến (categorical) theo một đại lượng khác, có thể là tần số của nhóm đó hoặc môt giá trị đo lường khác.

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut))

Thể hiện số lượng của từng nhóm của biến cut. Ta dễ dàng thấy số lượng của các nhóm tăng dẩn từ trái qua phải. Nhóm ideal có số lượng nhiều nhất.

ggplot(data = pressure) +
  geom_col(mapping = aes(x = temperature, y = pressure))

Cho thấy áp suất đo được trên từng khoảng nhiệt độ khác nhau. Ta cũng dễ dàng nhân ra được xu hướng “Nhiệt độ (temperature) càng tăng thì áp suất (pressure) cũng tăng theo”.

2.12 Các tham số khác của geom_bar() và geom_col()

2 hàm này có các thông số của aesthetics (aes()) sau:

alpha: mức độ đậm nhạt

color: màu sắc (của đường viền bên ngoài của mỗi cột)

fill: màu sắc của cả cột

width: kích thước (độ rộng) của cột

# color
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, color = cut))

# fill
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = cut))

# width
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = cut), width = 0.5)

2.13 Biểu đồ cột chồng

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity))

2.14 Biểu đồ cột ghép

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge")

2.15 Biểu đồ miền

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill")

2.16 Biểu đồ hộp

Boxplot là biểu đồ dùng để mô tả một biến định lượng theo một cách trực quan và đơn giản. Qua boxplot, chúng ta sẽ có thông tin về:

Median: Trung vị

Quartile: Tứ phân vị

IQR: Khoảng tứ phân vị

Min, max: giá trị lớn nhất, giá trị nhỏ nhất (không kể các outliers)

Outliers: Biến ngoại lai, giá trị nằm ngoài khoảng (Q1-1.5IQR; Q3+1.5IQR)

Ngoài ra ta có thể kiểm tra phân bố của biến liên tục có phải phân bố chuẩn hay không thông qua tính đối xứng trục của biểu đồ boxplot. Hình ảnh càng đối xứng thì phân bố của biến càng giống phân bố chuẩn.

ggplot(data = mpg) +
  geom_boxplot(mapping = aes(x = class, y = hwy))

3 Bài thực hành tuần 4

Tương tự với dữ liệu Tuần 1

## gọi package 'AER' xuất hiện 
library(AER)
## Warning: package 'AER' was built under R version 4.3.1
## Loading required package: car
## Loading required package: carData
## 
## Attaching package: 'carData'
## The following object is masked from 'package:Ecdat':
## 
##     Mroz
## 
## Attaching package: 'car'
## The following object is masked from 'package:purrr':
## 
##     some
## The following object is masked from 'package:dplyr':
## 
##     recode
## Loading required package: lmtest
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: survival
data(Journals)
## gán Journals vào d
d <- Journals
## cấu trúc của dataset Journals 
str(d)
## 'data.frame':    180 obs. of  10 variables:
##  $ title       : chr  "Asian-Pacific Economic Literature" "South African Journal of Economic History" "Computational Economics" "MOCT-MOST Economic Policy in Transitional Economics" ...
##  $ publisher   : Factor w/ 52 levels "ANU Press","Academic Press",..: 11 45 28 28 18 18 13 18 28 11 ...
##  $ society     : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ price       : int  123 20 443 276 295 344 90 242 226 262 ...
##  $ pages       : int  440 309 567 520 791 609 602 665 243 386 ...
##  $ charpp      : int  3822 1782 2924 3234 3024 2967 3185 2688 3010 2501 ...
##  $ citations   : int  21 22 22 22 24 24 24 27 28 30 ...
##  $ foundingyear: int  1986 1986 1987 1991 1972 1994 1995 1968 1987 1949 ...
##  $ subs        : int  14 59 17 2 96 15 14 202 46 46 ...
##  $ field       : Factor w/ 24 levels "General","Economic History",..: 1 2 3 4 5 6 7 3 4 1 ...
## đặt tên cho các biến có trong dữ liệu 
names(d) <- c('T','PU','SO','PR','PA','CH','CI','F','SU','FI')

Để thuận tiện cho việc thực hành, chúng ta sẽ sử dụng một số bộ dữ liệu (data set) đã có sẵn trong R.

Trong những ví dụ sau chúng ta sẽ sử dụng bộ dữ liệu journals để thực hiện thao tác vẽ đồ thị.

3.1 Giới thiệu dữ liệu

# gọi package ' ggplot2 ' xuất hiện
library(ggplot2)
data("journals")
## Warning in data("journals"): data set 'journals' not found

3.2 Biểu đồ

3.2.1 Biểu đồ hình tròn [ dùng pie()]

Sử dụng biến subs (số lượng đăng kí thư viện) để vẽ biểu đồ tròn dựa trên 5 nhóm phân loại đánh giá về số lượng đăng kí của người được khảo sát.

# phân 5 nhóm cho biến subs 
table(cut(d$SU,5))
## 
##   (0.904,221]     (221,440]     (440,660]     (660,879] (879,1.1e+03] 
##           124            32            17             5             2
# vẽ biểu đồ dựa trên 5 nhóm đã phân loại 
pie(table(cut(d$SU,5)))

. Màu trắng là nhóm giá trị từ khoảng 0,904 đến bằng 221

. Màu xanh lam là nhóm giá trị từ khoảng 221 đến bằng 440

. Màu hồng là nhóm giá trị từ khoảng 440 đến bằng 660

. Màu xanh mint là nhóm giá trị từ khoảng 660 đến bằng 879

. Màu tím là nhóm giá trị từ khoảng 879 đến bằng 1.1e + 03

3.2.2 Đồ thị phân phối xác xuất bằng hàm plot(density)

Đồ thị mật độ phân phối xác suất cho biến “Price” bằng hàm density()

plot(density(d$PR),add=TRUE)
## Warning in plot.window(...): "add" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "add" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter

## Warning in axis(side = side, at = at, labels = labels, ...): "add" is not a
## graphical parameter
## Warning in box(...): "add" is not a graphical parameter
## Warning in title(...): "add" is not a graphical parameter

Từ đồ thị cho thấy, phân phối của biến “price” giá sách từ 200 đến 500 là cao nhất và từ 500 đến 2500 trở đi phân phối ngày càng giảm dần. Điều đó có nghĩa là giá được khảo sát ở khoảng trung bình từ 200-500

3.2.3 Đồ thị dạng scatter

Biểu đồ phân tán (scatter plot):

Sử dụng các dấu chấm để thể hiện giá trị (điểm giao nhau) của hai biến số khác nhau.

Dùng để quan sát mối tương quan giữa 2 biến định lượng.

Trục hoành (trục X) mô tả biến độc lập. Trục tung (Y) mô tả biến phụ thuộc.

ggplot(data=iris, mapping = aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point()

3.2.4 Đồ thị cột

Biểu đồ cột mô tả các nhóm trong một biến (categorical) theo một đại lượng khác, có thể là tần số của nhóm đó hoặc môt giá trị đo lường khác.

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut))

Thể hiện số lượng của từng nhóm của biến cut. Ta dễ dàng thấy số lượng của các nhóm tăng dẩn từ trái qua phải. Nhóm ideal có số lượng nhiều nhất.

ggplot(data = pressure) +
  geom_col(mapping = aes(x = temperature, y = pressure))

Cho thấy áp suất đo được trên từng khoảng nhiệt độ khác nhau. Ta cũng dễ dàng nhân ra được xu hướng “Nhiệt độ (temperature) càng tăng thì áp suất (pressure) cũng tăng theo”.

3.2.4.1 Các tham số khác của geom_bar() và geom_col()

2 hàm này có các thông số của aesthetics (aes()) sau:

alpha: mức độ đậm nhạt

color: màu sắc (của đường viền bên ngoài của mỗi cột)

fill: màu sắc của cả cột

width: kích thước (độ rộng) của cột

# color
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, color = cut))

# fill
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = cut))

# width
ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = cut), width = 0.5)

3.2.4.2 Biểu đồ cột chồng

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity))

3.2.4.3 Biểu đồ cột ghép

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge")

3.2.4.4 Biểu đồ miền

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill")

3.2.5 Biểu đồ hộp

Boxplot là biểu đồ dùng để mô tả một biến định lượng theo một cách trực quan và đơn giản. Qua boxplot, chúng ta sẽ có thông tin về:

Median: Trung vị

Quartile: Tứ phân vị

IQR: Khoảng tứ phân vị

Min, max: giá trị lớn nhất, giá trị nhỏ nhất (không kể các outliers)

Outliers: Biến ngoại lai, giá trị nằm ngoài khoảng (Q1-1.5IQR; Q3+1.5IQR)

Ngoài ra ta có thể kiểm tra phân bố của biến liên tục có phải phân bố chuẩn hay không thông qua tính đối xứng trục của biểu đồ boxplot. Hình ảnh càng đối xứng thì phân bố của biến càng giống phân bố chuẩn.

ggplot(data = mpg) +
  geom_boxplot(mapping = aes(x = class, y = hwy))

4 Bài thực hành tuần 3

4.1 Giới thiệu Data frame

Data frame là dữ liệu dạng bảng có mối liên hệ 2 chiều (hàng và cột). Mỗi chiều đại diện cho 1 trường có cùng kiểu dữ liệu và mỗi dòng đại diện cho một bản ghi hay quan sát. Một data frame phải thỏa mãn những tính chất sau đây:

1.Tên của cột không được empty

2.Tên của dòng phải là duy nhất.

3.Kiểu dữ liệu của cột store trong data frame phải là numeric, factor và character.

4.Độ dài dữ liệu các cột phải bằng nhau.

Cú pháp để tạo một data frame trong R data.frame(vector1,vector2,…,StringsAsFactors = FALSE) trong đó vector1,vector2,… là các vector có cùng độ dài. StringAsFactors có tác dụng xác định một biến character có dạng factor hay không (factor có thể hiểu là các gía trị của một biến định tinh chẳng hạn như (nam, nữ), (quí 1, quí 2, quí 3, quí 4),…).

#Tạo một data frame
df <- data.frame(
  STT = c(seq(1,10,1)),
  Name = c("Khanh","Linh","Trang","Mai","Alex","Mari","Bayes","Jon","Jame","But"),
  Salary = rnorm(10,1000,200),
  Birday = as.Date(c("1993-07-09","1998-11-21","1994-06-09","1999-07-06","1992-05-19"            ,"1993-07-09","1998-11-21","1994-06-09","1999-07-06","1992-05-19")),
  stringsAsFactors = FALSE
)

df
##    STT  Name    Salary     Birday
## 1    1 Khanh 1018.3502 1993-07-09
## 2    2  Linh 1348.5890 1998-11-21
## 3    3 Trang  845.2979 1994-06-09
## 4    4   Mai 1025.4797 1999-07-06
## 5    5  Alex  566.2355 1992-05-19
## 6    6  Mari 1266.3154 1993-07-09
## 7    7 Bayes 1189.8614 1998-11-21
## 8    8   Jon 1135.6512 1994-06-09
## 9    9  Jame 1206.0948 1999-07-06
## 10  10   But  778.8028 1992-05-19

Để kiểm tra định dạng các biến trong một data.frame ta dùng hàm str(dataframe_name)

str(df)
## 'data.frame':    10 obs. of  4 variables:
##  $ STT   : num  1 2 3 4 5 6 7 8 9 10
##  $ Name  : chr  "Khanh" "Linh" "Trang" "Mai" ...
##  $ Salary: num  1018 1349 845 1025 566 ...
##  $ Birday: Date, format: "1993-07-09" "1998-11-21" ...

Chúng ta cũng có thể có một số thống kê cơ bản về các trường dữ liệu bằng hàm summary. Kết quả trả về sẽ gồm trung bình, min, max, median, các giá trị tới hạn của phân vị thứ 1,3

summary(df)
##       STT            Name               Salary           Birday          
##  Min.   : 1.00   Length:10          Min.   : 566.2   Min.   :1992-05-19  
##  1st Qu.: 3.25   Class :character   1st Qu.: 888.6   1st Qu.:1993-07-09  
##  Median : 5.50   Mode  :character   Median :1080.6   Median :1994-06-09  
##  Mean   : 5.50                      Mean   :1038.1   Mean   :1995-09-30  
##  3rd Qu.: 7.75                      3rd Qu.:1202.0   3rd Qu.:1998-11-21  
##  Max.   :10.00                      Max.   :1348.6   Max.   :1999-07-06

Bên cạnh đó một số package còn đưa ra được nhiều thông tin hơn chẳng hạn như basicStats (gói này chỉ hoạt động với các biến dạng numeric)

#neu chay bao loi khong thay fBasics package thi dung lenh install.package("fBasics")
library(fBasics)
## Warning: package 'fBasics' was built under R version 4.3.1
## 
## Attaching package: 'fBasics'
## The following object is masked from 'package:car':
## 
##     densityPlot
basicStats(df[,c(1,3)])
##                   STT       Salary
## nobs        10.000000    10.000000
## NAs          0.000000     0.000000
## Minimum      1.000000   566.235501
## Maximum     10.000000  1348.588956
## 1. Quartile  3.250000   888.560959
## 3. Quartile  7.750000  1202.036421
## Mean         5.500000  1038.067775
## Median       5.500000  1080.565471
## Sum         55.000000 10380.677749
## SE Mean      0.957427    77.234764
## LCL Mean     3.334149   863.350601
## UCL Mean     7.665851  1212.784949
## Variance     9.166667 59652.087452
## Stdev        3.027650   244.237768
## Skewness     0.000000    -0.539760
## Kurtosis    -1.561636    -1.063951

Truy cập các phần tử của data.frame như sau:

df
##    STT  Name    Salary     Birday
## 1    1 Khanh 1018.3502 1993-07-09
## 2    2  Linh 1348.5890 1998-11-21
## 3    3 Trang  845.2979 1994-06-09
## 4    4   Mai 1025.4797 1999-07-06
## 5    5  Alex  566.2355 1992-05-19
## 6    6  Mari 1266.3154 1993-07-09
## 7    7 Bayes 1189.8614 1998-11-21
## 8    8   Jon 1135.6512 1994-06-09
## 9    9  Jame 1206.0948 1999-07-06
## 10  10   But  778.8028 1992-05-19
#Lấy dòng thứ 2 của data.frame
df[,2]
##  [1] "Khanh" "Linh"  "Trang" "Mai"   "Alex"  "Mari"  "Bayes" "Jon"   "Jame" 
## [10] "But"
#Lấy cột thứ nhất của data.frame
df[1,]
##   STT  Name  Salary     Birday
## 1   1 Khanh 1018.35 1993-07-09
#Lấyphần tử dòng thứ 2 cột thứ 2
df[2,2]
## [1] "Linh"

4.2 Xoay trục dữ liệu

library(tidyr)
library(tidyverse)

4.3 Dùng lệnh Longer_Pivot để trình bày lại dữ liệu từ hàng thành cột (rút gọn bộ dữ liệu)

Ta dùng hàm pivot_longer() trong package tidyverse để làm “dài” dữ liệu , tăng số lượng hàng và giảm số lượng cột.

Đầu tiên , ta gọi package tidyverse xuất hiện.

Tiếp theo , sử dụng hàm pivot_longer() để gom các cột đã nêu ở trên (tương ứng với các cột có thứ tự từ 6 đến 10) thành 2 cột mới . Một cột có tên là ‘religion’ , chứa tên các yếu tố làm ảnh hưởng đến các giới tính (tên các cột cũ) và một cột tên ‘age’ , chứa các giá trị tương ứng.

relig_income
## # A tibble: 18 × 11
##    religion `<$10k` `$10-20k` `$20-30k` `$30-40k` `$40-50k` `$50-75k` `$75-100k`
##    <chr>      <dbl>     <dbl>     <dbl>     <dbl>     <dbl>     <dbl>      <dbl>
##  1 Agnostic      27        34        60        81        76       137        122
##  2 Atheist       12        27        37        52        35        70         73
##  3 Buddhist      27        21        30        34        33        58         62
##  4 Catholic     418       617       732       670       638      1116        949
##  5 Don’t k…      15        14        15        11        10        35         21
##  6 Evangel…     575       869      1064       982       881      1486        949
##  7 Hindu          1         9         7         9        11        34         47
##  8 Histori…     228       244       236       238       197       223        131
##  9 Jehovah…      20        27        24        24        21        30         15
## 10 Jewish        19        19        25        25        30        95         69
## 11 Mainlin…     289       495       619       655       651      1107        939
## 12 Mormon        29        40        48        51        56       112         85
## 13 Muslim         6         7         9        10         9        23         16
## 14 Orthodox      13        17        23        32        32        47         38
## 15 Other C…       9         7        11        13        13        14         18
## 16 Other F…      20        33        40        46        49        63         46
## 17 Other W…       5         2         3         4         2         7          3
## 18 Unaffil…     217       299       374       365       341       528        407
## # ℹ 3 more variables: `$100-150k` <dbl>, `>150k` <dbl>,
## #   `Don't know/refused` <dbl>
relig_income %>%
 pivot_longer(-religion, 
              names_to = "income", 
              values_to = "count")
## # A tibble: 180 × 3
##    religion income             count
##    <chr>    <chr>              <dbl>
##  1 Agnostic <$10k                 27
##  2 Agnostic $10-20k               34
##  3 Agnostic $20-30k               60
##  4 Agnostic $30-40k               81
##  5 Agnostic $40-50k               76
##  6 Agnostic $50-75k              137
##  7 Agnostic $75-100k             122
##  8 Agnostic $100-150k            109
##  9 Agnostic >150k                 84
## 10 Agnostic Don't know/refused    96
## # ℹ 170 more rows
who %>% pivot_longer(
  cols = new_sp_m014:newrel_f65,
  names_to = c("diagnosis", "gender", "age"),
  names_pattern = "new_?(.*)_(.)(.*)",
  values_to = "count"
)
## # A tibble: 405,440 × 8
##    country     iso2  iso3   year diagnosis gender age   count
##    <chr>       <chr> <chr> <dbl> <chr>     <chr>  <chr> <dbl>
##  1 Afghanistan AF    AFG    1980 sp        m      014      NA
##  2 Afghanistan AF    AFG    1980 sp        m      1524     NA
##  3 Afghanistan AF    AFG    1980 sp        m      2534     NA
##  4 Afghanistan AF    AFG    1980 sp        m      3544     NA
##  5 Afghanistan AF    AFG    1980 sp        m      4554     NA
##  6 Afghanistan AF    AFG    1980 sp        m      5564     NA
##  7 Afghanistan AF    AFG    1980 sp        m      65       NA
##  8 Afghanistan AF    AFG    1980 sp        f      014      NA
##  9 Afghanistan AF    AFG    1980 sp        f      1524     NA
## 10 Afghanistan AF    AFG    1980 sp        f      2534     NA
## # ℹ 405,430 more rows
anscombe
##    x1 x2 x3 x4    y1   y2    y3    y4
## 1  10 10 10  8  8.04 9.14  7.46  6.58
## 2   8  8  8  8  6.95 8.14  6.77  5.76
## 3  13 13 13  8  7.58 8.74 12.74  7.71
## 4   9  9  9  8  8.81 8.77  7.11  8.84
## 5  11 11 11  8  8.33 9.26  7.81  8.47
## 6  14 14 14  8  9.96 8.10  8.84  7.04
## 7   6  6  6  8  7.24 6.13  6.08  5.25
## 8   4  4  4 19  4.26 3.10  5.39 12.50
## 9  12 12 12  8 10.84 9.13  8.15  5.56
## 10  7  7  7  8  4.82 7.26  6.42  7.91
## 11  5  5  5  8  5.68 4.74  5.73  6.89
anscombe %>%
 pivot_longer(everything(),
   names_to = c(".value", "set"),
   names_pattern = "(.)(.)"
 )
## # A tibble: 44 × 3
##    set       x     y
##    <chr> <dbl> <dbl>
##  1 1        10  8.04
##  2 2        10  9.14
##  3 3        10  7.46
##  4 4         8  6.58
##  5 1         8  6.95
##  6 2         8  8.14
##  7 3         8  6.77
##  8 4         8  5.76
##  9 1        13  7.58
## 10 2        13  8.74
## # ℹ 34 more rows

4.4 Dùng lệnh Longer_wider để trình bày lại dữ liệu từ cột thành hàng

Trong một số trường hợp , ta muốn chuyển đổi bộ dữ liệu sang định dạng ngang thì ta có thể sử dụng hàm pivot_wider() , tăng số lượng cột và giảm số lượng dòng.

head(tidyr::fish_encounters)
## # A tibble: 6 × 3
##   fish  station  seen
##   <fct> <fct>   <int>
## 1 4842  Release     1
## 2 4842  I80_1       1
## 3 4842  Lisbon      1
## 4 4842  Rstr        1
## 5 4842  Base_TD     1
## 6 4842  BCE         1
tidyr::fish_encounters %>%
  pivot_wider(names_from = station, 
              values_from = seen)
## # A tibble: 19 × 12
##    fish  Release I80_1 Lisbon  Rstr Base_TD   BCE   BCW  BCE2  BCW2   MAE   MAW
##    <fct>   <int> <int>  <int> <int>   <int> <int> <int> <int> <int> <int> <int>
##  1 4842        1     1      1     1       1     1     1     1     1     1     1
##  2 4843        1     1      1     1       1     1     1     1     1     1     1
##  3 4844        1     1      1     1       1     1     1     1     1     1     1
##  4 4845        1     1      1     1       1    NA    NA    NA    NA    NA    NA
##  5 4847        1     1      1    NA      NA    NA    NA    NA    NA    NA    NA
##  6 4848        1     1      1     1      NA    NA    NA    NA    NA    NA    NA
##  7 4849        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
##  8 4850        1     1     NA     1       1     1     1    NA    NA    NA    NA
##  9 4851        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 10 4854        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 11 4855        1     1      1     1       1    NA    NA    NA    NA    NA    NA
## 12 4857        1     1      1     1       1     1     1     1     1    NA    NA
## 13 4858        1     1      1     1       1     1     1     1     1     1     1
## 14 4859        1     1      1     1       1    NA    NA    NA    NA    NA    NA
## 15 4861        1     1      1     1       1     1     1     1     1     1     1
## 16 4862        1     1      1     1       1     1     1     1     1    NA    NA
## 17 4863        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 18 4864        1     1     NA    NA      NA    NA    NA    NA    NA    NA    NA
## 19 4865        1     1      1    NA      NA    NA    NA    NA    NA    NA    NA
fish_encounters %>%
  pivot_wider(
    names_from = station,
    values_from = seen,
    values_fill = list(seen = 0)
  )
## # A tibble: 19 × 12
##    fish  Release I80_1 Lisbon  Rstr Base_TD   BCE   BCW  BCE2  BCW2   MAE   MAW
##    <fct>   <int> <int>  <int> <int>   <int> <int> <int> <int> <int> <int> <int>
##  1 4842        1     1      1     1       1     1     1     1     1     1     1
##  2 4843        1     1      1     1       1     1     1     1     1     1     1
##  3 4844        1     1      1     1       1     1     1     1     1     1     1
##  4 4845        1     1      1     1       1     0     0     0     0     0     0
##  5 4847        1     1      1     0       0     0     0     0     0     0     0
##  6 4848        1     1      1     1       0     0     0     0     0     0     0
##  7 4849        1     1      0     0       0     0     0     0     0     0     0
##  8 4850        1     1      0     1       1     1     1     0     0     0     0
##  9 4851        1     1      0     0       0     0     0     0     0     0     0
## 10 4854        1     1      0     0       0     0     0     0     0     0     0
## 11 4855        1     1      1     1       1     0     0     0     0     0     0
## 12 4857        1     1      1     1       1     1     1     1     1     0     0
## 13 4858        1     1      1     1       1     1     1     1     1     1     1
## 14 4859        1     1      1     1       1     0     0     0     0     0     0
## 15 4861        1     1      1     1       1     1     1     1     1     1     1
## 16 4862        1     1      1     1       1     1     1     1     1     0     0
## 17 4863        1     1      0     0       0     0     0     0     0     0     0
## 18 4864        1     1      0     0       0     0     0     0     0     0     0
## 19 4865        1     1      1     0       0     0     0     0     0     0     0
head(tidyr::us_rent_income)
## # A tibble: 6 × 5
##   GEOID NAME    variable estimate   moe
##   <chr> <chr>   <chr>       <dbl> <dbl>
## 1 01    Alabama income      24476   136
## 2 01    Alabama rent          747     3
## 3 02    Alaska  income      32940   508
## 4 02    Alaska  rent         1200    13
## 5 04    Arizona income      27517   148
## 6 04    Arizona rent          972     4
warpbreaks <- as_tibble(warpbreaks[c("wool", "tension", "breaks")])
head(warpbreaks, 10)
## # A tibble: 10 × 3
##    wool  tension breaks
##    <fct> <fct>    <dbl>
##  1 A     L           26
##  2 A     L           30
##  3 A     L           54
##  4 A     L           25
##  5 A     L           70
##  6 A     L           52
##  7 A     L           51
##  8 A     L           26
##  9 A     L           67
## 10 A     M           18
warpbreaks %>%
  pivot_wider(
    names_from = wool,
    values_from = breaks,
    values_fn = list(breaks = mean)
  )
## # A tibble: 3 × 3
##   tension     A     B
##   <fct>   <dbl> <dbl>
## 1 L        44.6  28.2
## 2 M        24    28.8
## 3 H        24.6  18.8

5 Bài thực hành tuần 2

5.1 Một số khái niệm

Mô tả: Dữ liệu Journals của gói AER là một dữ liệu Đăng ký các tạp chí kinh tế tại các thư viện Hoa Kỳ, cho năm 2000, trong đó gồm 10 biến.

1.title : tên tạp chí.

2.publisher : yếu tố với tên nhà xuất bản.

3.society : nhân tố. Là tạp chí được xuất bản bởi một xã hội học thuật?

4.price : Giá đăng ký thư viện.

5.pages : Số trang

6.charpp : Ký tự trên mỗi trang.

7.citations : Tổng số trích dẫn.

8.foundingyear : Tạp chí năm được thành lập.

9.subs : Số lượng đăng ký thư viện.

10.field : yếu tố với mô tả trường.

5.2 Lấy dữ liệu Journals

## gọi package 'AER' xuất hiện
library(AER)
data(Journals)
## gán Journals vào d
d <- Journals

5.3 Thực hành

no <- d[d$society == 'no',]
yes <- d[!d$society == 'no',]
### Cung cấp một bảng tóm tắt thống kê về dữ liệu 'giá đăng kí thư viện', ta dùng câu lệnh trên R, sau đó có được kết quả lần lượt là giá trị nhỏ nhất,giá trị phần tư thứ nhất,giá trị trung bình, giá trị trung vị, giá trị của phần tư thứ ba, giá trị lớn nhất
summary(d$price)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    20.0   134.5   282.0   417.7   540.8  2120.0
### nhóm các giá trị 
cut(d$price,4)
##   [1] (17.9,545]         (17.9,545]         (17.9,545]        
##   [4] (17.9,545]         (17.9,545]         (17.9,545]        
##   [7] (17.9,545]         (17.9,545]         (17.9,545]        
##  [10] (17.9,545]         (17.9,545]         (17.9,545]        
##  [13] (17.9,545]         (545,1.07e+03]     (17.9,545]        
##  [16] (17.9,545]         (17.9,545]         (17.9,545]        
##  [19] (17.9,545]         (17.9,545]         (17.9,545]        
##  [22] (17.9,545]         (17.9,545]         (17.9,545]        
##  [25] (545,1.07e+03]     (17.9,545]         (17.9,545]        
##  [28] (17.9,545]         (17.9,545]         (17.9,545]        
##  [31] (17.9,545]         (17.9,545]         (17.9,545]        
##  [34] (17.9,545]         (17.9,545]         (17.9,545]        
##  [37] (17.9,545]         (17.9,545]         (545,1.07e+03]    
##  [40] (545,1.07e+03]     (17.9,545]         (17.9,545]        
##  [43] (17.9,545]         (17.9,545]         (545,1.07e+03]    
##  [46] (17.9,545]         (17.9,545]         (17.9,545]        
##  [49] (17.9,545]         (17.9,545]         (17.9,545]        
##  [52] (17.9,545]         (17.9,545]         (17.9,545]        
##  [55] (17.9,545]         (17.9,545]         (17.9,545]        
##  [58] (17.9,545]         (17.9,545]         (17.9,545]        
##  [61] (17.9,545]         (17.9,545]         (545,1.07e+03]    
##  [64] (17.9,545]         (17.9,545]         (17.9,545]        
##  [67] (17.9,545]         (17.9,545]         (17.9,545]        
##  [70] (17.9,545]         (17.9,545]         (17.9,545]        
##  [73] (545,1.07e+03]     (545,1.07e+03]     (17.9,545]        
##  [76] (17.9,545]         (17.9,545]         (17.9,545]        
##  [79] (17.9,545]         (545,1.07e+03]     (17.9,545]        
##  [82] (17.9,545]         (17.9,545]         (545,1.07e+03]    
##  [85] (17.9,545]         (17.9,545]         (17.9,545]        
##  [88] (17.9,545]         (17.9,545]         (17.9,545]        
##  [91] (545,1.07e+03]     (17.9,545]         (17.9,545]        
##  [94] (17.9,545]         (1.07e+03,1.6e+03] (17.9,545]        
##  [97] (545,1.07e+03]     (545,1.07e+03]     (17.9,545]        
## [100] (17.9,545]         (17.9,545]         (17.9,545]        
## [103] (545,1.07e+03]     (17.9,545]         (17.9,545]        
## [106] (17.9,545]         (17.9,545]         (17.9,545]        
## [109] (17.9,545]         (545,1.07e+03]     (17.9,545]        
## [112] (545,1.07e+03]     (1.07e+03,1.6e+03] (545,1.07e+03]    
## [115] (545,1.07e+03]     (17.9,545]         (17.9,545]        
## [118] (17.9,545]         (17.9,545]         (1.07e+03,1.6e+03]
## [121] (17.9,545]         (545,1.07e+03]     (545,1.07e+03]    
## [124] (17.9,545]         (17.9,545]         (17.9,545]        
## [127] (545,1.07e+03]     (1.6e+03,2.12e+03] (17.9,545]        
## [130] (17.9,545]         (1.07e+03,1.6e+03] (17.9,545]        
## [133] (545,1.07e+03]     (17.9,545]         (545,1.07e+03]    
## [136] (545,1.07e+03]     (17.9,545]         (17.9,545]        
## [139] (1.07e+03,1.6e+03] (17.9,545]         (1.07e+03,1.6e+03]
## [142] (17.9,545]         (17.9,545]         (17.9,545]        
## [145] (545,1.07e+03]     (17.9,545]         (17.9,545]        
## [148] (545,1.07e+03]     (545,1.07e+03]     (1.07e+03,1.6e+03]
## [151] (1.07e+03,1.6e+03] (545,1.07e+03]     (17.9,545]        
## [154] (17.9,545]         (17.9,545]         (17.9,545]        
## [157] (17.9,545]         (545,1.07e+03]     (1.07e+03,1.6e+03]
## [160] (1.07e+03,1.6e+03] (1.07e+03,1.6e+03] (17.9,545]        
## [163] (17.9,545]         (17.9,545]         (17.9,545]        
## [166] (545,1.07e+03]     (17.9,545]         (17.9,545]        
## [169] (17.9,545]         (1.6e+03,2.12e+03] (1.07e+03,1.6e+03]
## [172] (17.9,545]         (1.07e+03,1.6e+03] (17.9,545]        
## [175] (17.9,545]         (17.9,545]         (17.9,545]        
## [178] (17.9,545]         (17.9,545]         (17.9,545]        
## Levels: (17.9,545] (545,1.07e+03] (1.07e+03,1.6e+03] (1.6e+03,2.12e+03]
### Phân tổ cho dữ liệu 'Giá' không đều và đặt tên theo từng tổ 'ít','vừa','nhiều' sau đó gán vào biến slcoded, ta được kết quả là:
d$sl <- cut(d$price, breaks = c(17.9,201,354,878),labels = c('ít','vừa','nhiều'))
### Tạo bảng tần số cho dữ lệu 'Giá' được chia thành tổ không đều ở trên, ta dùng câu lệnh trên R, sau đó ta được kết quả là  những lần xuất hiện của từng tổ 'ít','vừa,'nhiều'
table(d$sl)
## 
##    ít   vừa nhiều 
##    66    35    57
### Dùng để tính giá trị trung bình của biến 'Giá'
mean(d$price)
## [1] 417.7222
### Dùng để tính phương sai dựa vào dữ liệu của biến 'Giá'
var(d$price)
## [1] 148868.3
### Dùng để tính độ lệch chuẩn của biến 'Giá', Độ lệch chuẩn là thước đo độ phân tán hoặc trải rộng của các điểm dữ liệu xung quanh giá trị trung bình.
sd(d$price)
## [1] 385.8346
### tính tổng các giá trị trong cột'Giá'của tập dữ liệu "d".
sum(d$price)
## [1] 75190
### Tính giá trung bình của cột 'Giá'trong tập dữ liệu d cho từng nhân tố 
aggregate(d$price, list(d$society), FUN = 'mean')
##   Group.1        x
## 1      no 435.4695
## 2     yes 235.8125
### Tính phương sai của cột 'Giá' trong tập dữ liệu d cho từng nhân tố
aggregate(d$price, list(d$society), FUN = 'var')
##   Group.1        x
## 1      no 148920.7
## 2     yes 119483.2
### Tính độ lệch chuẩn của cột 'Giá' trong tập dữ liệu d cho từng  nhân tố
aggregate(d$price, list(d$society), FUN = 'sd')
##   Group.1        x
## 1      no 385.9024
## 2     yes 345.6635
### Tính tổng của cột 'Giá' trong tập dữ d cho từng nhân tố 
aggregate(d$price, list(d$society), FUN = 'sum')
##   Group.1     x
## 1      no 71417
## 2     yes  3773
### Để tính toán thống kê tóm tắt của cột "giá" trong tập dữ liệu "d" được nhóm theo các giá trị duy nhất trong cột "nhân tố". Nó sẽ cung cấp các tóm tắt thống kê như tối thiểu, phần tư thứ nhất, trung bình, trung vị, phần tư thứ 3 và tối đa cho mỗi nhóm.
aggregate(d$price, list(d$society), FUN = 'summary')
##   Group.1    x.Min. x.1st Qu.  x.Median    x.Mean x.3rd Qu.    x.Max.
## 1      no   20.0000  162.2500  317.5000  435.4695  567.5000 2120.0000
## 2     yes   45.0000   49.2500   96.5000  235.8125  190.0000 1154.0000

6 Bài thực hành tuần 1

Thao tác trên dataset

## gọi package 'AER' xuất hiện 
library(AER)
data(Journals)
## gán Journals vào d
d <- Journals
## cấu trúc của dataset Journals 
str(d)
## 'data.frame':    180 obs. of  10 variables:
##  $ title       : chr  "Asian-Pacific Economic Literature" "South African Journal of Economic History" "Computational Economics" "MOCT-MOST Economic Policy in Transitional Economics" ...
##  $ publisher   : Factor w/ 52 levels "ANU Press","Academic Press",..: 11 45 28 28 18 18 13 18 28 11 ...
##  $ society     : Factor w/ 2 levels "no","yes": 1 1 1 1 1 1 1 1 1 1 ...
##  $ price       : int  123 20 443 276 295 344 90 242 226 262 ...
##  $ pages       : int  440 309 567 520 791 609 602 665 243 386 ...
##  $ charpp      : int  3822 1782 2924 3234 3024 2967 3185 2688 3010 2501 ...
##  $ citations   : int  21 22 22 22 24 24 24 27 28 30 ...
##  $ foundingyear: int  1986 1986 1987 1991 1972 1994 1995 1968 1987 1949 ...
##  $ subs        : int  14 59 17 2 96 15 14 202 46 46 ...
##  $ field       : Factor w/ 24 levels "General","Economic History",..: 1 2 3 4 5 6 7 3 4 1 ...
## đặt tên cho các biến có trong dữ liệu 
names(d) <- c('T','PU','SO','PR','PA','CH','CI','F','SU','FI')

Tới đây đã xong một số việc.

## đọc 6 dầu đầu tiên của dữ liệu
head(d)
##                                                          T
## APEL                     Asian-Pacific Economic Literature
## SAJoEH           South African Journal of Economic History
## CE                                 Computational Economics
## MEPiTE MOCT-MOST Economic Policy in Transitional Economics
## JoSE                            Journal of Socio-Economics
## LabEc                                     Labour Economics
##                            PU SO  PR  PA   CH CI    F SU                FI
## APEL                Blackwell no 123 440 3822 21 1986 14           General
## SAJoEH So Afr ec history assn no  20 309 1782 22 1986 59  Economic History
## CE                     Kluwer no 443 567 2924 22 1987 17       Specialized
## MEPiTE                 Kluwer no 276 520 3234 22 1991  2      Area Studies
## JoSE                 Elsevier no 295 791 3024 24 1972 96 Interdisciplinary
## LabEc                Elsevier no 344 609 2967 24 1994 15             Labor
## đọc 6 dòng cuối cùng của dữ liệu 
tail(d)
##                                                       T                    PU
## JASA    Journal of the American Statistical Association  Am. Statistical Assn
## JoFi                                 Journal of Finance      Am. Finance Assn
## QJoE                     Quarterly Journal of Economics             MIT press
## JoPolEc                    Journal of Political Economy Univ of Chicago Press
## Ecnmt                                      Econometrica             Blackwell
## AER                            American Economic Review            Am Ec Assn
##          SO  PR   PA   CH   CI    F   SU           FI
## JASA    yes 310 1260 5664 2800 1971  487 Econometrics
## JoFi    yes 226 2272 3036 3791 1945  799      Finance
## QJoE     no 148 1467 2184 4138 1886  660      General
## JoPolEc  no 159 1669 2640 6697 1892  737      General
## Ecnmt   yes 178 1482 2992 7943 1932  346      General
## AER     yes  47 1867 3900 8999 1911 1098      General
Vol <- d$SU 
Vol
##   [1]   14   59   17    2   96   15   14  202   46   46   57  125   30   62   16
##  [16]   17   37  148  110   16   30   61   27   45   15   25  203  646   59   27
##  [31]   31  532   52   87   27  291    9   24   49   24  323   69   21  212   14
##  [46]   38   22   77  290  386   50  144   48   33   29   58   71  135  183  573
##  [61]  268   57   52   21  479   77   89   83   59   67  225   56   36  101  288
##  [76]  183   25  120  263  101   43   73  221   83   37  185   61   57  186  199
##  [91]  165   95   82  214  152   33   81  137   59   98  163  462   99   52   47
## [106]  394  227   65  242  154   45   81   79  120   91  218   97  322  283   40
## [121]  552  222   29  390   95  305   98  146  271  515  172  127   58  524  222
## [136]  385  413  366   75  238  142  437  269  643  230  313  512  211  171   34
## [151]   81  144  190  339  771  522  284  202  118  160  141  972  542  866  267
## [166]  186  558  523  325  129  165  531  231  536  487  799  660  737  346 1098
Vol15 <- Vol[Vol > 50 & Vol < 90]
Voll <- d[d$PR >  50 |d$T < 70,]
vol <- d$b_l
vol50 <- vol[vol<50]