Summer Olympic medals 1976 to 2008

CSV to JSON

> setwd("C:/Users/vlado/DL/data/kaggle/Olympic")
> library(jsonlite)
> library(Polychrome)
> library(magrittr)
> source("https://raw.githubusercontent.com/bavla/ibm3m/master/multiway/MWnets.R")

> # OL <- read.csv("Summer-Olympic-medals-1976-to-2008.csv") # rows 772-888 are empty; save UTF-8
> OL <- read.csv("Olympic.csv",fileEncoding="UTF-8")
> dim(OL)
> str(OL)
> OL$Olympics <- paste(OL$City,OL$Year)
> MT <- DF2MWN(OL,c("Olympics","Sport","Discipline","Event","Gender","Country","Medal"),
+   network="Olympic",title="Summer Olympic medals 1976 to 2008")
> str(MT)

> MT$info$URL <- "https://github.com/kalilurrahman/dataset"
> names(MT$links)[1] <- "w"

> L <- MT$links
> Links <- aggregate(L$w,
+   by=list(L$Olympics,L$Sport,L$Discipline,L$Event,L$Gender,L$Country,L$Medal),
+   FUN=sum)
> names(Links) <- c("Olympics","Sport","Discipline","Event","Gender","Country","Medal","w")
> MT$links <- Links
> str(MT)
List of 6
 $ format: chr "MWnets"
 $ info  :List of 5
  ..$ network: chr "Olympic"
  ..$ title  : chr "Summer Olympic medals 1976 to 2008"
  ..$ by     : chr "DF2MWN"
  ..$ date   : chr "Wed Feb  1 03:53:17 2023"
  ..$ URL    : chr "https://github.com/kalilurrahman/dataset"
 $ ways  :List of 7
  ..$ Olympics  : chr "Olympics"
  ..$ Sport     : chr "Sport"
  ..$ Discipline: chr "Discipline"
  ..$ Event     : chr "Event"
  ..$ Gender    : chr "Gender"
  ..$ Country   : chr "Country"
  ..$ Medal     : chr "Medal"
 $ nodes :List of 7
  ..$ Olympics  :'data.frame':  9 obs. of  1 variable:
  .. ..$ ID: chr [1:9] "Athens 2004" "Atlanta 1996" "Barcelona 1992" "Beijing 2008" ...
  ..$ Sport     :'data.frame':  28 obs. of  1 variable:
  .. ..$ ID: chr [1:28] "Aquatics" "Archery" "Athletics" "Badminton" ...
  ..$ Discipline:'data.frame':  41 obs. of  1 variable:
  .. ..$ ID: chr [1:41] "Archery" "Artistic G." "Athletics" "Badminton" ...
  ..$ Event     :'data.frame':  293 obs. of  1 variable:
  .. ..$ ID: chr [1:293] "- 48 kg" "- 48kg" "- 48kg (extra-lightweight)" "- 48kg (light-flyweight)" ...
  ..$ Gender    :'data.frame':  2 obs. of  1 variable:
  .. ..$ ID: chr [1:2] "Men" "Women"
  ..$ Country   :'data.frame':  127 obs. of  1 variable:
  .. ..$ ID: chr [1:127] "Afghanistan" "Algeria" "Argentina" "Armenia" ...
  ..$ Medal     :'data.frame':  3 obs. of  1 variable:
  .. ..$ ID: chr [1:3] "Bronze" "Gold" "Silver"
 $ links :'data.frame': 7186 obs. of  8 variables:
  ..$ Olympics  : int [1:7186] 4 3 9 2 5 5 9 9 4 9 ...
  ..$ Sport     : int [1:7186] 23 7 7 7 7 7 3 3 16 19 ...
  ..$ Discipline: int [1:7186] 33 9 9 9 9 9 3 3 21 27 ...
  ..$ Event     : int [1:7186] 10 94 110 141 141 146 154 214 68 65 ...
  ..$ Gender    : int [1:7186] 1 1 1 1 1 1 1 1 2 1 ...
  ..$ Country   : int [1:7186] 1 2 2 2 2 2 2 2 2 3 ...
  ..$ Medal     : int [1:7186] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ w         : num [1:7186] 1 1 1 1 1 1 1 1 1 2 ...
 $ data  : list()
> write(toJSON(MT),"Olympics0.json") 

Multiway network ((Olympics, Country, Discipline), w)

> MD <- MT
> L <- MD$links
> Links <- aggregate(L$w,by=list(L$Olympics,L$Country,L$Discipline),FUN=sum)
> names(Links) <- c("Olympics","Country","Discipline","w")
> MD$links <- Links
> ways <- c("Olympics","Country","Discipline"); Ways <- as.list(ways); names(Ways) <- ways
> MD$ways <- Ways
> MD$nodes <- list(MT$nodes$Olympics,MT$nodes$Country,MT$nodes$Discipline)
> names(MD$nodes) <- ways
> str(MD)
List of 6
 $ format: chr "MWnets"
 $ info  :List of 5
  ..$ network: chr "Olympic"
  ..$ title  : chr "Summer Olympic medals 1976 to 2008"
  ..$ by     : chr "DF2MWN"
  ..$ date   : chr "Wed Feb  1 03:53:17 2023"
  ..$ URL    : chr "https://github.com/kalilurrahman/dataset"
 $ ways  :List of 3
  ..$ Olympics  : chr "Olympics"
  ..$ Country   : chr "Country"
  ..$ Discipline: chr "Discipline"
 $ nodes :List of 3
  ..$ Olympics  :'data.frame':  9 obs. of  1 variable:
  .. ..$ ID: chr [1:9] "Athens 2004" "Atlanta 1996" "Barcelona 1992" "Beijing 2008" ...
  ..$ Country   :'data.frame':  127 obs. of  1 variable:
  .. ..$ ID: chr [1:127] "Afghanistan" "Algeria" "Argentina" "Armenia" ...
  ..$ Discipline:'data.frame':  41 obs. of  1 variable:
  .. ..$ ID: chr [1:41] "Archery" "Artistic G." "Athletics" "Badminton" ...
 $ links :'data.frame': 2843 obs. of  4 variables:
  ..$ Olympics  : int [1:2843] 1 9 1 2 3 4 5 3 7 3 ...
  ..$ Country   : int [1:2843] 5 5 19 19 19 19 19 36 36 37 ...
  ..$ Discipline: int [1:2843] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ w         : num [1:2843] 1 1 3 1 3 7 1 3 2 1 ...
 $ data  : list()
> write(toJSON(MD),"Olympics1.json")

Olympics pSum core; Olympics pRel core / Disciplines;

vlado/work/2m/mwn/olymp.txt · Last modified: 2023/02/04 03:23 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki