ืืจืื ืืืงืจืื, ืืืฉืจ ืขืืืืื ืขื ืชืืืื ืฉืืชืงืืื ื-API, ืื ืขื ืื ื ืชืื ืืืจ ืฉืืฉ ืื ืืื ื ืขืฅ ืืืจืื, ืืชื ืืชืืืื ืขื ืคืืจืืืื ืฉื JSON ื-XML.
ืืคืืจืืืื ืืืื ืืฉ ืืชืจืื ืืช ืจืืื: ืื ืืืืกื ืื ื ืชืื ืื ืืฆืืจื ืงืืืคืงืืืช ืืืื ืืืืคืฉืจืื ืืื ืืข ืฉืืคืื ืืืืข ืืืืชืจ.
ืืืืกืจืื ืฉื ืคืืจืืืื ืืื ืืื ืืืจืืืืช ืืขืืืื ืืื ืืชืื ืฉืืื. ืื ื ืืชื ืืืฉืชืืฉ ืื ืชืื ืื ืื ืืืื ืื ืืืืฉืืืื ืืื ื ืืชื ืืื ืืช ืขืืืื ืืืืื.
ืืืืจ ืื ืืื ืืืฉื ืืืืื ื ืฉื ืืคืจืกืื tidyr
, ืืืืืืื ืืืืืช ืืกืคืจืืื tidyverse
, ืืืฉืคืืช ืืคืื ืงืฆืืืช ืฉืื unnest_*()
.
ืชืืื
ืื ืืชื ืืขืื ืืื ืื ืืชืื ื ืชืื ืื, ืืืื ืืชื ืืขืื ืืื ื- ืฉืื
ืืืื ืืฉืชืืฉื GitHub ืืืืจื Github ืืืืืืช ืืฉืืงื ืืืก ืงืืืื ืืืืืืจืคื ืขื ืืืื ืืืกืงืืืจืคืื ืฉื ืฉืจืื ืืืคื ื ืืกืงื ื
ืืืื
ืืืื (ืืขืจืช ืืืชืจืื, ืื ืืฆืืชื ืืคืฉืจืืืืช ืชืจืืื ืืชืืืืืช ืืืื ื ืืื, ืื ื ืฉืืืจ ืืืชื ืืื ืฉืืื.) ืืื ืชืืืื ืืืืช ื ืชืื ืื ืื ืืืื ืื ืขื ืืขืจืืื ืืงืื ื ืื ืืืืื ืื ืืืืืืช ืืืืจืืืช ืืฉืืจืืช ืืขืืืืืช ืืืืจืืช. IN tidyr
ืืฉื ื ืืกืคืจ ืคืื ืงืฆืืืช ืฉืืขืืจื ืื ืืืจืืื ืืช ืขืืืืืช ืืจืฉืืื ืืืงืื ื ืืช ืืืืงืืื ืืช ืื ืชืื ืื ืืฆืืจื ืืืื ืืช ืืืืื:
unnest_longer()
ืืืงื ืื ืจืืื ืืจืฉืืืช ืืขืืืืืช ืืืืฆืจ ืฉืืจื ืืืฉื.unnest_wider()
ืืืงื ืื ืจืืื ืืจืฉืืืช ืืขืืืืืช ืืืืฆืจ ืขืืืื ืืืฉื.unnest_auto()
ืงืืืข ืืืืืืืืช ืืืืื ืคืื ืงืฆืื ืืื ืืืื ืืืฉืชืืฉ
unnest_longer()
ืืunnest_wider()
.hoist()
ืืืื ืunnest_wider()
ืืื ืืืืจ ืจืง ืืช ืืจืืืืื ืฉืฆืืื ื ืืืืคืฉืจ ืื ืืขืืื ืขื ืืกืคืจ ืจืืืช ืฉื ืงืื ืื.
ื ืืชื ืืคืชืืจ ืืช ืจืื ืืืขืืืช ืืงืฉืืจืืช ืืืืืช ื ืชืื ืื ืื ืืืื ืื ืขื ืืกืคืจ ืจืืืช ืฉื ืงืื ืื ืืืืื ืื ืืืืืืช ืขื ืืื ืฉืืืื ืืคืื ืงืฆืืืช ืืืคืืจืืืช ืขื dplyr.
ืืื ืืืืืื ืืช ืืืื ืืงืืช ืืืื, ื ืฉืชืืฉ ืืืืืื repurrrsive
, ืืืกืคืง ืจืฉืืืืช ืืืจืืืืช ืืจืืืืช ืจืืืช ืื ืืืจืืช ื-API ืืื ืืจื ื.
library(tidyr)
library(dplyr)
library(repurrrsive)
ืืฉืชืืฉื GitHub
ืืืื ื ืชืืื ืขื gh_users, ืจืฉืืื ืืืืืื ืืืืข ืขื ืฉืืฉื ืืฉืชืืฉื GitHub. ืจืืฉืืช ืืืื ื ืฉื ื ืืช ืืจืฉืืื gh_users ะฒ ืืื ืึดืกืึถืจึถืช:
users <- tibble( user = gh_users )
ืื ื ืจืื ืงืฆืช ืื ืืื ืืืื ืืืืืฆืื: ืืื ืืกืคืง ืจืฉืืื gh_users, ืืืื ื ื ืชืื ืื ืืืจืื ืืืชืจ? ืืื ืืืกืืจืช ื ืชืื ืื ืืฉ ืืชืจืื ืืืื: ืืื ืืฉืืืช ืืงืืืจืื ืืจืืืื ืื ืฉืืื ื ืืฆื ืืืขืงื ืืืืืืืงื ืืื.
ืื ืจืืื ืืืืืืงื users
ืืื ืจืฉืืื ืืขืืช ืฉื ืฉืื ืื ืจืืื ืืืืฆื ืขืืืื.
names(users$user[[1]])
#> [1] "login" "id" "avatar_url"
#> [4] "gravatar_id" "url" "html_url"
#> [7] "followers_url" "following_url" "gists_url"
#> [10] "starred_url" "subscriptions_url" "organizations_url"
#> [13] "repos_url" "events_url" "received_events_url"
#> [16] "type" "site_admin" "name"
#> [19] "company" "blog" "location"
#> [22] "email" "hireable" "bio"
#> [25] "public_repos" "public_gists" "followers"
#> [28] "following" "created_at" "updated_at"
ืืฉื ื ืฉืชื ืืจืืื ืืืคืื ืจืืืื ืจืฉืืื ืืขืืืืืช. unnest_wider()
ืืืงื ืื ืจืืื ืืืืฆืจ ืขืืืื ืืืฉื:
users %>% unnest_wider(user)
#> # A tibble: 6 x 30
#> login id avatar_url gravatar_id url html_url followers_url
#> <chr> <int> <chr> <chr> <chr> <chr> <chr>
#> 1 gaboโฆ 6.60e5 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 2 jennโฆ 5.99e5 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 3 jtleโฆ 1.57e6 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 4 juliโฆ 1.25e7 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 5 leepโฆ 3.51e6 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 6 masaโฆ 8.36e6 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> # โฆ with 23 more variables: following_url <chr>, gists_url <chr>,
#> # starred_url <chr>, subscriptions_url <chr>, organizations_url <chr>,
#> # repos_url <chr>, events_url <chr>, received_events_url <chr>,
#> # type <chr>, site_admin <lgl>, name <chr>, company <chr>, blog <chr>,
#> # location <chr>, email <chr>, public_repos <int>, public_gists <int>,
#> # followers <int>, following <int>, created_at <chr>, updated_at <chr>,
#> # bio <chr>, hireable <lgl>
ืืืงืจื ืื, ืืฉ ืื ื ืืืื ืืืืจืืืช ื-30 ืขืืืืืช, ืืื ื ืฆืืจื ืืช ืจืืื, ืื ื ืืื ืืืงืื ืืืช unnest_wider()
ืฉืืืืฉ hoist()
. hoist()
ืืืคืฉืจ ืื ื ืืืืฅ ืจืืืืื ื ืืืจืื ืืืืฆืขืืช ืืืชื ืชืืืืจ ืืื purrr::pluck()
:
users %>% hoist(user,
followers = "followers",
login = "login",
url = "html_url"
)
#> # A tibble: 6 x 4
#> followers login url user
#> <int> <chr> <chr> <list>
#> 1 303 gaborcsardi https://github.com/gaborcsardi <named list [27]>
#> 2 780 jennybc https://github.com/jennybc <named list [27]>
#> 3 3958 jtleek https://github.com/jtleek <named list [27]>
#> 4 115 juliasilge https://github.com/juliasilge <named list [27]>
#> 5 213 leeper https://github.com/leeper <named list [27]>
#> 6 34 masalmon https://github.com/masalmon <named list [27]>
hoist()
ืืกืืจ ืืช ืืจืืืืื ืืขืื ืืฉื ืฉืฆืืื ื ืืจืฉืืืช ืขืืืืืช ืืืฉืชืืฉืื ืืชื ืืืื ืืฉืงืื hoist()
ืืื ืืขืืจืช ืจืืืืื ืืืจืฉืืื ืืคื ืืืืช ืฉื ืืกืืจืช ืชืืจืื ืืจืื ืืขืืืื ื ืฉืื.
ืืืืจื Github
ืืืฉืืจ ืจืฉืืื gh_repos
ืื ื ืืชืืืืื ืืืืคื ืืืื ืขื ืืื ืืืจืชื ื tibble
:
repos <- tibble(repo = gh_repos)
repos
#> # A tibble: 6 x 1
#> repo
#> <list>
#> 1 <list [30]>
#> 2 <list [30]>
#> 3 <list [30]>
#> 4 <list [26]>
#> 5 <list [30]>
#> 6 <list [30]>
ืืคืขื ืืืืื ืืื ืืืฉืชืืฉ ืืืืฆืืื ืจืฉืืื ืฉื ืืืืจืื ืืืขืืืช ืืฉืชืืฉ ืื. ืื ืืืืจ ืืื ืชืฆืคืืช ื ืคืจืืช, ืื ืืคื ืืจืขืืื ืฉื ื ืชืื ืื ืืกืืืจืื (ืืขืจื ื ืชืื ืื ืืกืืืจืื) ืื ืฆืจืืืื ืืืคืื ืืฉืืจืืช ืืืฉืืช, ืืื ืืกืืื ืฉืื ื ืืฉืชืืฉืื unnest_longer()
ืืื unnest_wider()
:
repos <- repos %>% unnest_longer(repo)
repos
#> # A tibble: 176 x 1
#> repo
#> <list>
#> 1 <named list [68]>
#> 2 <named list [68]>
#> 3 <named list [68]>
#> 4 <named list [68]>
#> 5 <named list [68]>
#> 6 <named list [68]>
#> 7 <named list [68]>
#> 8 <named list [68]>
#> 9 <named list [68]>
#> 10 <named list [68]>
#> # โฆ with 166 more rows
ืขืืฉืื ืื ืื ื ืืืืืื ืืืฉืชืืฉ unnest_wider()
ืื hoist()
:
repos %>% hoist(repo,
login = c("owner", "login"),
name = "name",
homepage = "homepage",
watchers = "watchers_count"
)
#> # A tibble: 176 x 5
#> login name homepage watchers repo
#> <chr> <chr> <chr> <int> <list>
#> 1 gaborcsardi after <NA> 5 <named list [65]>
#> 2 gaborcsardi argufy <NA> 19 <named list [65]>
#> 3 gaborcsardi ask <NA> 5 <named list [65]>
#> 4 gaborcsardi baseimports <NA> 0 <named list [65]>
#> 5 gaborcsardi citest <NA> 0 <named list [65]>
#> 6 gaborcsardi clisymbols "" 18 <named list [65]>
#> 7 gaborcsardi cmaker <NA> 0 <named list [65]>
#> 8 gaborcsardi cmark <NA> 0 <named list [65]>
#> 9 gaborcsardi conditions <NA> 0 <named list [65]>
#> 10 gaborcsardi crayon <NA> 52 <named list [65]>
#> # โฆ with 166 more rows
ืฉืืื ืื ืืฉืืืืฉ c("owner", "login")
: ืื ืืืคืฉืจ ืื ื ืืงืื ืืช ืขืจื ืืจืื ืืฉื ืืื ืืจืฉืืื ืืงืื ื ืช owner
. ืืืฉื ืืืืคืืช ืืื ืืงืื ืืช ืื ืืจืฉืืื owner
ืืืืืจ ืืื ืืืืฆืขืืช ืืคืื ืงืฆืื unnest_wider()
ืฉืื ืื ืืื ืืืจืืืืื ืฉืื ืืขืืืื:
repos %>%
hoist(repo, owner = "owner") %>%
unnest_wider(owner)
#> # A tibble: 176 x 18
#> login id avatar_url gravatar_id url html_url followers_url
#> <chr> <int> <chr> <chr> <chr> <chr> <chr>
#> 1 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 2 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 3 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 4 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 5 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 6 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 7 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 8 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 9 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> 10 gaboโฆ 660288 https://aโฆ "" httpโฆ https:/โฆ https://api.โฆ
#> # โฆ with 166 more rows, and 11 more variables: following_url <chr>,
#> # gists_url <chr>, starred_url <chr>, subscriptions_url <chr>,
#> # organizations_url <chr>, repos_url <chr>, events_url <chr>,
#> # received_events_url <chr>, type <chr>, site_admin <lgl>, repo <list>
ืืืงืื ืืืฉืื ืขื ืืืืจืช ืืคืื ืงืฆืื ืื ืืื ื unnest_longer()
ืื unnest_wider()
ืืชื ืืืื ืืืฉืชืืฉ unnest_auto()
. ืคืื ืงืฆืื ืื ืืฉืชืืฉืช ืืืกืคืจ ืฉืืืืช ืืืืจืืกืืืืช ืืื ืืืืืจ ืืช ืืคืื ืงืฆืื ืืืชืืืื ืืืืชืจ ืืืืจืช ืื ืชืื ืื, ืืืฆืืื ืืืืขื ืขื ืืฉืืื ืฉื ืืืจื.
tibble(repo = gh_repos) %>%
unnest_auto(repo) %>%
unnest_auto(repo)
#> Using `unnest_longer(repo)`; no element has names
#> Using `unnest_wider(repo)`; elements have 68 names in common
#> # A tibble: 176 x 67
#> id name full_name owner private html_url description fork url
#> <int> <chr> <chr> <lis> <lgl> <chr> <chr> <lgl> <chr>
#> 1 6.12e7 after gaborcsaโฆ <namโฆ FALSE https:/โฆ Run Code iโฆ FALSE httpโฆ
#> 2 4.05e7 arguโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ Declarativโฆ FALSE httpโฆ
#> 3 3.64e7 ask gaborcsaโฆ <namโฆ FALSE https:/โฆ Friendly Cโฆ FALSE httpโฆ
#> 4 3.49e7 baseโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ Do we get โฆ FALSE httpโฆ
#> 5 6.16e7 citeโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ Test R pacโฆ TRUE httpโฆ
#> 6 3.39e7 clisโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ Unicode syโฆ FALSE httpโฆ
#> 7 3.72e7 cmakโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ port of cmโฆ TRUE httpโฆ
#> 8 6.80e7 cmark gaborcsaโฆ <namโฆ FALSE https:/โฆ CommonMarkโฆ TRUE httpโฆ
#> 9 6.32e7 condโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ <NA> TRUE httpโฆ
#> 10 2.43e7 crayโฆ gaborcsaโฆ <namโฆ FALSE https:/โฆ R package โฆ FALSE httpโฆ
#> # โฆ with 166 more rows, and 58 more variables: forks_url <chr>,
#> # keys_url <chr>, collaborators_url <chr>, teams_url <chr>,
#> # hooks_url <chr>, issue_events_url <chr>, events_url <chr>,
#> # assignees_url <chr>, branches_url <chr>, tags_url <chr>,
#> # blobs_url <chr>, git_tags_url <chr>, git_refs_url <chr>,
#> # trees_url <chr>, statuses_url <chr>, languages_url <chr>,
#> # stargazers_url <chr>, contributors_url <chr>, subscribers_url <chr>,
#> # subscription_url <chr>, commits_url <chr>, git_commits_url <chr>,
#> # comments_url <chr>, issue_comment_url <chr>, contents_url <chr>,
#> # compare_url <chr>, merges_url <chr>, archive_url <chr>,
#> # downloads_url <chr>, issues_url <chr>, pulls_url <chr>,
#> # milestones_url <chr>, notifications_url <chr>, labels_url <chr>,
#> # releases_url <chr>, deployments_url <chr>, created_at <chr>,
#> # updated_at <chr>, pushed_at <chr>, git_url <chr>, ssh_url <chr>,
#> # clone_url <chr>, svn_url <chr>, size <int>, stargazers_count <int>,
#> # watchers_count <int>, language <chr>, has_issues <lgl>,
#> # has_downloads <lgl>, has_wiki <lgl>, has_pages <lgl>,
#> # forks_count <int>, open_issues_count <int>, forks <int>,
#> # open_issues <int>, watchers <int>, default_branch <chr>,
#> # homepage <chr>
ืืืืืืช ืืฉืืงื ืืืก
got_chars
ืืขื ืืื ื ืืื ื gh_users
: ืืืื ืงืืืฆื ืฉื ืจืฉืืืืช ืขื ืฉื, ืืืฉืจ ืื ืจืืื ืืจืฉืืื ืืคื ืืืืช ืืชืืจ ืชืืื ื ืืืฉืื ืฉื ืืืืช ืืฉืืงื ืืืก. ืืืื got_chars
ืขืืืจ ืชืฆืืืช ืืืืื, ืื ื ืืชืืืืื ืืืฆืืจืช ืืกืืจืช ืชืืจืื, ืืืืืง ืืื ืืืืืืืืช ืืงืืืืืช, ืืืืืจ ืืื ืืืืจืื ืื ืืืื ื ืืขืืืื ื ืคืจืืช:
chars <- tibble(char = got_chars)
chars
#> # A tibble: 30 x 1
#> char
#> <list>
#> 1 <named list [18]>
#> 2 <named list [18]>
#> 3 <named list [18]>
#> 4 <named list [18]>
#> 5 <named list [18]>
#> 6 <named list [18]>
#> 7 <named list [18]>
#> 8 <named list [18]>
#> 9 <named list [18]>
#> 10 <named list [18]>
#> # โฆ with 20 more rows
chars2 <- chars %>% unnest_wider(char)
chars2
#> # A tibble: 30 x 18
#> url id name gender culture born died alive titles aliases father
#> <chr> <int> <chr> <chr> <chr> <chr> <chr> <lgl> <list> <list> <chr>
#> 1 httpโฆ 1022 Theoโฆ Male Ironboโฆ In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 2 httpโฆ 1052 Tyriโฆ Male "" In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 3 httpโฆ 1074 Victโฆ Male Ironboโฆ In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 4 httpโฆ 1109 Will Male "" "" In 2โฆ FALSE <chr โฆ <chr [โฆ ""
#> 5 httpโฆ 1166 Areoโฆ Male Norvosโฆ In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 6 httpโฆ 1267 Chett Male "" At Hโฆ In 2โฆ FALSE <chr โฆ <chr [โฆ ""
#> 7 httpโฆ 1295 Cresโฆ Male "" In 2โฆ In 2โฆ FALSE <chr โฆ <chr [โฆ ""
#> 8 httpโฆ 130 Ariaโฆ Female Dornish In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 9 httpโฆ 1303 Daenโฆ Female Valyriโฆ In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> 10 httpโฆ 1319 Davoโฆ Male Westerโฆ In 2โฆ "" TRUE <chr โฆ <chr [โฆ ""
#> # โฆ with 20 more rows, and 7 more variables: mother <chr>, spouse <chr>,
#> # allegiances <list>, books <list>, povBooks <list>, tvSeries <list>,
#> # playedBy <list>
ืืื ื got_chars
ืงืฆืช ืืืชืจ ืงืฉื ื gh_users
, ืื ืืื ืจืืืื ืจืฉืืื char
ืขืฆืื ืื ืจืฉืืื, ืืชืืฆืื ืืื ืื ื ืืงืืืื ืขืืืืื - ืจืฉืืืืช:
chars2 %>% select_if(is.list)
#> # A tibble: 30 x 7
#> titles aliases allegiances books povBooks tvSeries playedBy
#> <list> <list> <list> <list> <list> <list> <list>
#> 1 <chr [3]> <chr [4]> <chr [1]> <chr [3]> <chr [2]> <chr [6]> <chr [1]>
#> 2 <chr [2]> <chr [11]> <chr [1]> <chr [2]> <chr [4]> <chr [6]> <chr [1]>
#> 3 <chr [2]> <chr [1]> <chr [1]> <chr [3]> <chr [2]> <chr [1]> <chr [1]>
#> 4 <chr [1]> <chr [1]> <???> <chr [1]> <chr [1]> <chr [1]> <chr [1]>
#> 5 <chr [1]> <chr [1]> <chr [1]> <chr [3]> <chr [2]> <chr [2]> <chr [1]>
#> 6 <chr [1]> <chr [1]> <???> <chr [2]> <chr [1]> <chr [1]> <chr [1]>
#> 7 <chr [1]> <chr [1]> <???> <chr [2]> <chr [1]> <chr [1]> <chr [1]>
#> 8 <chr [1]> <chr [1]> <chr [1]> <chr [4]> <chr [1]> <chr [1]> <chr [1]>
#> 9 <chr [5]> <chr [11]> <chr [1]> <chr [1]> <chr [4]> <chr [6]> <chr [1]>
#> 10 <chr [4]> <chr [5]> <chr [2]> <chr [1]> <chr [3]> <chr [5]> <chr [1]>
#> # โฆ with 20 more rows
ืืคืขืืืืช ืื ืืกืคืืช ืฉืื ืชืืืืืช ืืืืจืืช ืื ืืชืื. ืืืื ืืชื ืฆืจืื ืืฉืื ืืืืข ืขื ืืฉืืจืืช ืขืืืจ ืื ืกืคืจ ืืกืืจื ืฉืืื ืืืืืช ืืืคืืขื:
chars2 %>%
select(name, books, tvSeries) %>%
pivot_longer(c(books, tvSeries), names_to = "media", values_to = "value") %>%
unnest_longer(value)
#> # A tibble: 180 x 3
#> name media value
#> <chr> <chr> <chr>
#> 1 Theon Greyjoy books A Game of Thrones
#> 2 Theon Greyjoy books A Storm of Swords
#> 3 Theon Greyjoy books A Feast for Crows
#> 4 Theon Greyjoy tvSeries Season 1
#> 5 Theon Greyjoy tvSeries Season 2
#> 6 Theon Greyjoy tvSeries Season 3
#> 7 Theon Greyjoy tvSeries Season 4
#> 8 Theon Greyjoy tvSeries Season 5
#> 9 Theon Greyjoy tvSeries Season 6
#> 10 Tyrion Lannister books A Feast for Crows
#> # โฆ with 170 more rows
ืื ืืืื ืืชื ืจืืฆื ืืืฆืืจ ืืืื ืฉืชืืคืฉืจ ืื ืืืชืืื ืืช ืืืืืช ืืืืฆืืจื:
chars2 %>%
select(name, title = titles) %>%
unnest_longer(title)
#> # A tibble: 60 x 2
#> name title
#> <chr> <chr>
#> 1 Theon Greyjoy Prince of Winterfell
#> 2 Theon Greyjoy Captain of Sea Bitch
#> 3 Theon Greyjoy Lord of the Iron Islands (by law of the green lands)
#> 4 Tyrion Lannister Acting Hand of the King (former)
#> 5 Tyrion Lannister Master of Coin (former)
#> 6 Victarion Greyjoy Lord Captain of the Iron Fleet
#> 7 Victarion Greyjoy Master of the Iron Victory
#> 8 Will ""
#> 9 Areo Hotah Captain of the Guard at Sunspear
#> 10 Chett ""
#> # โฆ with 50 more rows
(ืฉืื ืื ืืขืจืืื ืืจืืงืื ""
ืืชืืื title
, ืื ื ืืืข ืืฉืืืืืช ืฉื ืขืฉื ืืขืช ืืื ืช ื ืชืื ืื got_chars
: ืืืขืฉื, ืืืืืืช ืฉืืื ืืื ืืืชืจืืช ืกืคืจ ืืกืืจืืช ืืืืืืืื ืืงืืืืืช ืืชืืื title
ืืืื ืืืืืช ืืงืืืจ ืืืืจื 0, ืื ืืงืืืจ ืืืืจื 1 ืืืืื ืืช ืืืืจืืืช ืืจืืงื.)
ืื ื ืืืืืื ืืฉืืชื ืืช ืืืืืื ืืขืื ืืืืฆืขืืช ืืคืื ืงืฆืื unnest_auto()
. ืืืฉื ืื ื ืืื ืื ืืชืื ืื ืคืขืื, ืื ืืื ืืืกืชืื ืขืืื unnest_auto()
ืืฉืืืืฉ ืขื ืืกืืก ืงืืืข. ืื ืงืืื ืืื ืฉืื ืืื ื ืื ืชืื ืื ืฉืื ืืฉืชื ื unnest_auto()
ืืืื ืืฉื ืืช ืืช ืื ืื ืื ืืืจืช ืื ืชืื ืื ืฉื ืืืจ ืื ืืื ืืจืืื ืชืืืื ืขืืืืืช ืจืฉืืื ืืฉืืจืืช ืืืืฆืขืืช unnest_longer()
, ืื ืืืฉืจ ืืื ื ืื ืชืื ืื ืื ืื ืกืื ืืฉืชื ื, ื ืืชื ืืฉื ืืช ืืช ืืืืืืื ืืืืืชื unnest_wider()
, ืืฉืืืืฉ ืืืืฉื ืื ืืืืคื ืฉืืืฃ ืขืืื ืืืืืื ืืฉืืืืืช ืืืชื ืฆืคืืืืช.
tibble(char = got_chars) %>%
unnest_auto(char) %>%
select(name, title = titles) %>%
unnest_auto(title)
#> Using `unnest_wider(char)`; elements have 18 names in common
#> Using `unnest_longer(title)`; no element has names
#> # A tibble: 60 x 2
#> name title
#> <chr> <chr>
#> 1 Theon Greyjoy Prince of Winterfell
#> 2 Theon Greyjoy Captain of Sea Bitch
#> 3 Theon Greyjoy Lord of the Iron Islands (by law of the green lands)
#> 4 Tyrion Lannister Acting Hand of the King (former)
#> 5 Tyrion Lannister Master of Coin (former)
#> 6 Victarion Greyjoy Lord Captain of the Iron Fleet
#> 7 Victarion Greyjoy Master of the Iron Victory
#> 8 Will ""
#> 9 Areo Hotah Captain of the Guard at Sunspear
#> 10 Chett ""
#> # โฆ with 50 more rows
ืงืืืื ืืืืืืจืคื ืขื ืืืื
ืืืืจ ืืื, ื ืืื ืืื ื ืืืจืื ืืืชืจ ืฉื ืื ืชืื ืื ืืืชืงืืืื ืืฉืืจืืช ืืงืืืื ืืืืืืืจืคื ืฉื ืืืื. ืฉืืืจื ืืืืืื ืื ืืืืช ืืืืื ืืขืืืื ืขื ื-API ืฉื ืืคืืช Google, ืื ืื ื ืืืชืื ืชืืืื ืขืืืคื ืคืฉืืื ืกืืื ื-API. ืืฉืจ ืืืืกืก ืขื ืืืกืื ืืคืชื ื-API ืฉื Google Maps ืืืฉืชื ื ืกืืืื; ืื ืืื ืื ืืช ืืืคืชื ืืขืืืื ืขื Google Maps API ืืืืืืกื ืืืฉืชื ื ืืกืืืื ืฉืื, ืงืืขื ืืงืื ืืืืฆืืื ืืกืขืืฃ ืื ืื ืืืืฆืขื.
has_key <- !identical(Sys.getenv("GOOGLE_MAPS_API_KEY"), "")
if (!has_key) {
message("No Google Maps API key found; code chunks will not be run")
}
# https://developers.google.com/maps/documentation/geocoding
geocode <- function(address, api_key = Sys.getenv("GOOGLE_MAPS_API_KEY")) {
url <- "https://maps.googleapis.com/maps/api/geocode/json"
url <- paste0(url, "?address=", URLencode(address), "&key=", api_key)
jsonlite::read_json(url)
}
ืืจืฉืืื ืฉืืคืื ืงืฆืื ืืื ืืืืืจื ืืื ืื ืืืจืืืช:
houston <- geocode("Houston TX")
str(houston)
#> List of 2
#> $ results:List of 1
#> ..$ :List of 5
#> .. ..$ address_components:List of 4
#> .. .. ..$ :List of 3
#> .. .. .. ..$ long_name : chr "Houston"
#> .. .. .. ..$ short_name: chr "Houston"
#> .. .. .. ..$ types :List of 2
#> .. .. .. .. ..$ : chr "locality"
#> .. .. .. .. ..$ : chr "political"
#> .. .. ..$ :List of 3
#> .. .. .. ..$ long_name : chr "Harris County"
#> .. .. .. ..$ short_name: chr "Harris County"
#> .. .. .. ..$ types :List of 2
#> .. .. .. .. ..$ : chr "administrative_area_level_2"
#> .. .. .. .. ..$ : chr "political"
#> .. .. ..$ :List of 3
#> .. .. .. ..$ long_name : chr "Texas"
#> .. .. .. ..$ short_name: chr "TX"
#> .. .. .. ..$ types :List of 2
#> .. .. .. .. ..$ : chr "administrative_area_level_1"
#> .. .. .. .. ..$ : chr "political"
#> .. .. ..$ :List of 3
#> .. .. .. ..$ long_name : chr "United States"
#> .. .. .. ..$ short_name: chr "US"
#> .. .. .. ..$ types :List of 2
#> .. .. .. .. ..$ : chr "country"
#> .. .. .. .. ..$ : chr "political"
#> .. ..$ formatted_address : chr "Houston, TX, USA"
#> .. ..$ geometry :List of 4
#> .. .. ..$ bounds :List of 2
#> .. .. .. ..$ northeast:List of 2
#> .. .. .. .. ..$ lat: num 30.1
#> .. .. .. .. ..$ lng: num -95
#> .. .. .. ..$ southwest:List of 2
#> .. .. .. .. ..$ lat: num 29.5
#> .. .. .. .. ..$ lng: num -95.8
#> .. .. ..$ location :List of 2
#> .. .. .. ..$ lat: num 29.8
#> .. .. .. ..$ lng: num -95.4
#> .. .. ..$ location_type: chr "APPROXIMATE"
#> .. .. ..$ viewport :List of 2
#> .. .. .. ..$ northeast:List of 2
#> .. .. .. .. ..$ lat: num 30.1
#> .. .. .. .. ..$ lng: num -95
#> .. .. .. ..$ southwest:List of 2
#> .. .. .. .. ..$ lat: num 29.5
#> .. .. .. .. ..$ lng: num -95.8
#> .. ..$ place_id : chr "ChIJAYWNSLS4QIYROwVl894CDco"
#> .. ..$ types :List of 2
#> .. .. ..$ : chr "locality"
#> .. .. ..$ : chr "political"
#> $ status : chr "OK"
ืืืจืื ืืืื, ืื ื ืืืืืื ืืคืชืืจ ืืช ืืืขืื ืฉื ืืืจืช ื ืชืื ืื ืืื ืืืืคืก ืืืื ืฆืขื ืืืจ ืฆืขื ืืืืฆืขืืช ืคืื ืงืฆืืืช tidyr
. ืืื ืืืคืื ืืช ืืืฉืืื ืืงืฆืช ืืืชืจ ืืืชืืจืช ืืืฆืืืืชืืช, ืืชืืื ืืงืืืื ืืืืืืจืคื ืฉื ืืื ืขืจืื:
city <- c ( "Houston" , "LA" , "New York" , "Chicago" , "Springfield" ) city_geo <- purrr::map (city, geocode)
ืื ื ืืืืจ ืืช ืืชืืฆืื ืืืชืงืืืช ื tibble
, ืืืขืื ื ืืืืช, ืืืกืืฃ ืขืืืื ืขื ืฉื ืืขืืจ ืืืชืืื.
loc <- tibble(city = city, json = city_geo)
loc
#> # A tibble: 5 x 2
#> city json
#> <chr> <list>
#> 1 Houston <named list [2]>
#> 2 LA <named list [2]>
#> 3 New York <named list [2]>
#> 4 Chicago <named list [2]>
#> 5 Springfield <named list [2]>
ืืจืื ืืจืืฉืื ื ืืืืื ืจืืืืื status
ะธ result
, ืฉืืืชื ื ืืื ืืืจืืื unnest_wider()
:
loc %>%
unnest_wider(json)
#> # A tibble: 5 x 3
#> city results status
#> <chr> <list> <chr>
#> 1 Houston <list [1]> OK
#> 2 LA <list [1]> OK
#> 3 New York <list [1]> OK
#> 4 Chicago <list [1]> OK
#> 5 Springfield <list [1]> OK
ืฉืื ืื ืฉ results
ืืื ืจืฉืืื ืืจืืืช ืจืืืช. ืืจืื ืืขืจืื ืืฉ ืืืื ื ืืื (ืืืืืฆื ืขืจื ืืืืืื ืืืชืืื ื-API ืฉื ืงืืืื ืืืืืืจืคื), ืืื ืืกืคืจืื ืืคืืื ืืฉ ืฉื ืืื. ืื ืื ื ืืืืืื ืืืฉืื ืืืชื ืืฉืืจืืช ื ืคืจืืืช ืขื unnest_longer()
:
loc %>%
unnest_wider(json) %>%
unnest_longer(results)
#> # A tibble: 5 x 3
#> city results status
#> <chr> <list> <chr>
#> 1 Houston <named list [5]> OK
#> 2 LA <named list [5]> OK
#> 3 New York <named list [5]> OK
#> 4 Chicago <named list [5]> OK
#> 5 Springfield <named list [5]> OK
ืืขืช ืืืืื ืืฉ ืืช ืืืชื ืจืืืืื, ืืืชื ื ืืชื ืืืืช ืืืืฆืขืืช unnest_wider()
:
loc %>%
unnest_wider(json) %>%
unnest_longer(results) %>%
unnest_wider(results)
#> # A tibble: 5 x 7
#> city address_componenโฆ formatted_addreโฆ geometry place_id types status
#> <chr> <list> <chr> <list> <chr> <lis> <chr>
#> 1 Houstโฆ <list [4]> Houston, TX, USA <named โฆ ChIJAYWNโฆ <lisโฆ OK
#> 2 LA <list [4]> Los Angeles, CAโฆ <named โฆ ChIJE9onโฆ <lisโฆ OK
#> 3 New Yโฆ <list [3]> New York, NY, Uโฆ <named โฆ ChIJOwg_โฆ <lisโฆ OK
#> 4 Chicaโฆ <list [4]> Chicago, IL, USA <named โฆ ChIJ7cv0โฆ <lisโฆ OK
#> 5 Sprinโฆ <list [5]> Springfield, MOโฆ <named โฆ ChIJP5jIโฆ <lisโฆ OK
ื ืืื ืืืฆืื ืืช ืงืืืืจืืื ืืืช ืงืืื ืืจืืื ืืืืืจื ืฉื ืื ืขืืจ ืขื ืืื ืืจืืืช ืืจืฉืืื geometry
:
loc %>%
unnest_wider(json) %>%
unnest_longer(results) %>%
unnest_wider(results) %>%
unnest_wider(geometry)
#> # A tibble: 5 x 10
#> city address_componeโฆ formatted_addreโฆ bounds location location_type
#> <chr> <list> <chr> <list> <list> <chr>
#> 1 Housโฆ <list [4]> Houston, TX, USA <nameโฆ <named โฆ APPROXIMATE
#> 2 LA <list [4]> Los Angeles, CAโฆ <nameโฆ <named โฆ APPROXIMATE
#> 3 New โฆ <list [3]> New York, NY, Uโฆ <nameโฆ <named โฆ APPROXIMATE
#> 4 Chicโฆ <list [4]> Chicago, IL, USA <nameโฆ <named โฆ APPROXIMATE
#> 5 Spriโฆ <list [5]> Springfield, MOโฆ <nameโฆ <named โฆ APPROXIMATE
#> # โฆ with 4 more variables: viewport <list>, place_id <chr>, types <list>,
#> # status <chr>
ืืื ืืืืงืื ืฉืขืืืจื ืืชื ืฆืจืื ืืืจืืื location
:
loc %>%
unnest_wider(json) %>%
unnest_longer(results) %>%
unnest_wider(results) %>%
unnest_wider(geometry) %>%
unnest_wider(location)
#> # A tibble: 5 x 11
#> city address_componeโฆ formatted_addreโฆ bounds lat lng location_type
#> <chr> <list> <chr> <list> <dbl> <dbl> <chr>
#> 1 Housโฆ <list [4]> Houston, TX, USA <nameโฆ 29.8 -95.4 APPROXIMATE
#> 2 LA <list [4]> Los Angeles, CAโฆ <nameโฆ 34.1 -118. APPROXIMATE
#> 3 New โฆ <list [3]> New York, NY, Uโฆ <nameโฆ 40.7 -74.0 APPROXIMATE
#> 4 Chicโฆ <list [4]> Chicago, IL, USA <nameโฆ 41.9 -87.6 APPROXIMATE
#> 5 Spriโฆ <list [5]> Springfield, MOโฆ <nameโฆ 37.2 -93.3 APPROXIMATE
#> # โฆ with 4 more variables: viewport <list>, place_id <chr>, types <list>,
#> # status <chr>
ืืืื ืืืช ืฉืื ืคืขื, unnest_auto()
ืืคืฉื ืืช ืืคืขืืื ืืืชืืืจืช ืขื ืืื ืกืืืื ืื ืฉืขืืืืื ืืืืืจื ืืฉืื ืื ืืื ื ืื ืชืื ืื ืื ืื ืกืื:
loc %>%
unnest_auto(json) %>%
unnest_auto(results) %>%
unnest_auto(results) %>%
unnest_auto(geometry) %>%
unnest_auto(location)
#> Using `unnest_wider(json)`; elements have 2 names in common
#> Using `unnest_longer(results)`; no element has names
#> Using `unnest_wider(results)`; elements have 5 names in common
#> Using `unnest_wider(geometry)`; elements have 4 names in common
#> Using `unnest_wider(location)`; elements have 2 names in common
#> # A tibble: 5 x 11
#> city address_componeโฆ formatted_addreโฆ bounds lat lng location_type
#> <chr> <list> <chr> <list> <dbl> <dbl> <chr>
#> 1 Housโฆ <list [4]> Houston, TX, USA <nameโฆ 29.8 -95.4 APPROXIMATE
#> 2 LA <list [4]> Los Angeles, CAโฆ <nameโฆ 34.1 -118. APPROXIMATE
#> 3 New โฆ <list [3]> New York, NY, Uโฆ <nameโฆ 40.7 -74.0 APPROXIMATE
#> 4 Chicโฆ <list [4]> Chicago, IL, USA <nameโฆ 41.9 -87.6 APPROXIMATE
#> 5 Spriโฆ <list [5]> Springfield, MOโฆ <nameโฆ 37.2 -93.3 APPROXIMATE
#> # โฆ with 4 more variables: viewport <list>, place_id <chr>, types <list>,
#> # status <chr>
ืื ืื ื ืืืืืื ืื ืคืฉืื ืืืกืชืื ืขื ืืืชืืืช ืืจืืฉืื ื ืฉื ืื ืขืืจ:
loc %>%
unnest_wider(json) %>%
hoist(results, first_result = 1) %>%
unnest_wider(first_result) %>%
unnest_wider(geometry) %>%
unnest_wider(location)
#> # A tibble: 5 x 11
#> city address_componeโฆ formatted_addreโฆ bounds lat lng location_type
#> <chr> <list> <chr> <list> <dbl> <dbl> <chr>
#> 1 Housโฆ <list [4]> Houston, TX, USA <nameโฆ 29.8 -95.4 APPROXIMATE
#> 2 LA <list [4]> Los Angeles, CAโฆ <nameโฆ 34.1 -118. APPROXIMATE
#> 3 New โฆ <list [3]> New York, NY, Uโฆ <nameโฆ 40.7 -74.0 APPROXIMATE
#> 4 Chicโฆ <list [4]> Chicago, IL, USA <nameโฆ 41.9 -87.6 APPROXIMATE
#> 5 Spriโฆ <list [5]> Springfield, MOโฆ <nameโฆ 37.2 -93.3 APPROXIMATE
#> # โฆ with 4 more variables: viewport <list>, place_id <chr>, types <list>,
#> # status <chr>
ืื ืืืฉืชืืฉ hoist()
ืืฆืืืื ืืจืืืช ืจืืืช ืืืืช ืืฉืืจืืช ืืืื lat
ะธ lng
.
loc %>%
hoist(json,
lat = list("results", 1, "geometry", "location", "lat"),
lng = list("results", 1, "geometry", "location", "lng")
)
#> # A tibble: 5 x 4
#> city lat lng json
#> <chr> <dbl> <dbl> <list>
#> 1 Houston 29.8 -95.4 <named list [2]>
#> 2 LA 34.1 -118. <named list [2]>
#> 3 New York 40.7 -74.0 <named list [2]>
#> 4 Chicago 41.9 -87.6 <named list [2]>
#> 5 Springfield 37.2 -93.3 <named list [2]>
ืืืกืงืืืจืคืื ืฉื ืฉืจืื ืืืคื ื
ืืืกืืฃ, ื ืืื ืืช ืืืื ื ืืืืจืื ืืืืชืจ - ืืืืกืงืืืจืคืื ืฉื ืฉืจืื ืืืคื ื. ืืื ืืืืืืืืช ืืืขืื, ืื ื ืืชืืืืื ืืืืจืช ืืจืฉืืื ืืืกืืจืช ื ืชืื ืื ืฉื ืขืืืื ืืืช, ืืืืืจ ืืื ืืจืืืืื ืืืชื ืื ืฉืื ืจืืื ืืืื ืขืืืื ื ืคืจืืช. ืื ืื ื ืืฉื ื ืืช ืืขืืืื date_added
ืืคืืจืื ืืชืืจืื ืืืฉืขื ืืืชืืื ื-R.
discs <- tibble(disc = discog) %>%
unnest_wider(disc) %>%
mutate(date_added = as.POSIXct(strptime(date_added, "%Y-%m-%dT%H:%M:%S")))
discs
#> # A tibble: 155 x 5
#> instance_id date_added basic_information id rating
#> <int> <dttm> <list> <int> <int>
#> 1 354823933 2019-02-16 17:48:59 <named list [11]> 7496378 0
#> 2 354092601 2019-02-13 14:13:11 <named list [11]> 4490852 0
#> 3 354091476 2019-02-13 14:07:23 <named list [11]> 9827276 0
#> 4 351244906 2019-02-02 11:39:58 <named list [11]> 9769203 0
#> 5 351244801 2019-02-02 11:39:37 <named list [11]> 7237138 0
#> 6 351052065 2019-02-01 20:40:53 <named list [11]> 13117042 0
#> 7 350315345 2019-01-29 15:48:37 <named list [11]> 7113575 0
#> 8 350315103 2019-01-29 15:47:22 <named list [11]> 10540713 0
#> 9 350314507 2019-01-29 15:44:08 <named list [11]> 11260950 0
#> 10 350314047 2019-01-29 15:41:35 <named list [11]> 11726853 0
#> # โฆ with 145 more rows
ืืจืื ืื, ืื ื ืืงืืืื ืืืืข ืขื ืืชื ืื ืืืกืง ืืชืืืกืฃ ืืืืกืงืืืจืคืื ืฉื ืฉืจืื, ืื ืืื ื ื ืจืืืื ื ืชืื ืื ืขื ืืืืกืงืื ืืืื. ืืฉื ืื ืขืืื ื ืืืจืืื ืืช ืืขืืืื basic_information
:
discs %>% unnest_wider(basic_information)
#> Column name `id` must not be duplicated.
#> Use .name_repair to specify repair.
ืืฆืขืจื ื, ื ืงืื ืฉืืืื, ืื... ืืชืื ืืจืฉืืื basic_information
ืืฉ ืขืืืื ืืืืชื ืฉื basic_information
. ืื ืืชืจืืฉืช ืฉืืืื ืืื, ืืื ืืงืืืข ืืืืืจืืช ืืช ืืกืืื ืื, ืืชื ืืืื ืืืฉืชืืฉ names_repair = "unique"
:
discs %>% unnest_wider(basic_information, names_repair = "unique")
#> New names:
#> * id -> id...6
#> * id -> id...14
#> # A tibble: 155 x 15
#> instance_id date_added labels year artists id...6 thumb title
#> <int> <dttm> <list> <int> <list> <int> <chr> <chr>
#> 1 354823933 2019-02-16 17:48:59 <listโฆ 2015 <list โฆ 7.50e6 httpโฆ Demo
#> 2 354092601 2019-02-13 14:13:11 <listโฆ 2013 <list โฆ 4.49e6 httpโฆ Obseโฆ
#> 3 354091476 2019-02-13 14:07:23 <listโฆ 2017 <list โฆ 9.83e6 httpโฆ I
#> 4 351244906 2019-02-02 11:39:58 <listโฆ 2017 <list โฆ 9.77e6 httpโฆ Oรญdoโฆ
#> 5 351244801 2019-02-02 11:39:37 <listโฆ 2015 <list โฆ 7.24e6 httpโฆ A Caโฆ
#> 6 351052065 2019-02-01 20:40:53 <listโฆ 2019 <list โฆ 1.31e7 httpโฆ Tashโฆ
#> 7 350315345 2019-01-29 15:48:37 <listโฆ 2014 <list โฆ 7.11e6 httpโฆ Demo
#> 8 350315103 2019-01-29 15:47:22 <listโฆ 2015 <list โฆ 1.05e7 httpโฆ Let โฆ
#> 9 350314507 2019-01-29 15:44:08 <listโฆ 2017 <list โฆ 1.13e7 "" Sub โฆ
#> 10 350314047 2019-01-29 15:41:35 <listโฆ 2017 <list โฆ 1.17e7 httpโฆ Demo
#> # โฆ with 145 more rows, and 7 more variables: formats <list>,
#> # cover_image <chr>, resource_url <chr>, master_id <int>,
#> # master_url <chr>, id...14 <int>, rating <int>
ืืืขืื ืืื basic_information
ืืืืจ ืขื ืขืืืืช ืืืืื ืืืืืืกื ืช ืื ืืจืื ืืขืืืื ื, ืื ืฉื ืืื ืคืฉืื ืืืกืืจ ืืืชื:
discs %>%
select(-id) %>%
unnest_wider(basic_information)
#> # A tibble: 155 x 14
#> instance_id date_added labels year artists id thumb title
#> <int> <dttm> <list> <int> <list> <int> <chr> <chr>
#> 1 354823933 2019-02-16 17:48:59 <listโฆ 2015 <list โฆ 7.50e6 httpโฆ Demo
#> 2 354092601 2019-02-13 14:13:11 <listโฆ 2013 <list โฆ 4.49e6 httpโฆ Obseโฆ
#> 3 354091476 2019-02-13 14:07:23 <listโฆ 2017 <list โฆ 9.83e6 httpโฆ I
#> 4 351244906 2019-02-02 11:39:58 <listโฆ 2017 <list โฆ 9.77e6 httpโฆ Oรญdoโฆ
#> 5 351244801 2019-02-02 11:39:37 <listโฆ 2015 <list โฆ 7.24e6 httpโฆ A Caโฆ
#> 6 351052065 2019-02-01 20:40:53 <listโฆ 2019 <list โฆ 1.31e7 httpโฆ Tashโฆ
#> 7 350315345 2019-01-29 15:48:37 <listโฆ 2014 <list โฆ 7.11e6 httpโฆ Demo
#> 8 350315103 2019-01-29 15:47:22 <listโฆ 2015 <list โฆ 1.05e7 httpโฆ Let โฆ
#> 9 350314507 2019-01-29 15:44:08 <listโฆ 2017 <list โฆ 1.13e7 "" Sub โฆ
#> 10 350314047 2019-01-29 15:41:35 <listโฆ 2017 <list โฆ 1.17e7 httpโฆ Demo
#> # โฆ with 145 more rows, and 6 more variables: formats <list>,
#> # cover_image <chr>, resource_url <chr>, master_id <int>,
#> # master_url <chr>, rating <int>
ืืืืืคืื, ื ืืื ืืืฉืชืืฉ hoist()
:
discs %>%
hoist(basic_information,
title = "title",
year = "year",
label = list("labels", 1, "name"),
artist = list("artists", 1, "name")
)
#> # A tibble: 155 x 9
#> instance_id date_added title year label artist
#> <int> <dttm> <chr> <int> <chr> <chr>
#> 1 354823933 2019-02-16 17:48:59 Demo 2015 Tobiโฆ Mollot
#> 2 354092601 2019-02-13 14:13:11 Obseโฆ 2013 La Vโฆ Una Bโฆ
#> 3 354091476 2019-02-13 14:07:23 I 2017 La Vโฆ S.H.Iโฆ
#> 4 351244906 2019-02-02 11:39:58 Oรญdoโฆ 2017 La Vโฆ Rata โฆ
#> 5 351244801 2019-02-02 11:39:37 A Caโฆ 2015 Katoโฆ Ivy (โฆ
#> 6 351052065 2019-02-01 20:40:53 Tashโฆ 2019 Highโฆ Tashme
#> 7 350315345 2019-01-29 15:48:37 Demo 2014 Mindโฆ Desgrโฆ
#> 8 350315103 2019-01-29 15:47:22 Let โฆ 2015 Not โฆ Phantโฆ
#> 9 350314507 2019-01-29 15:44:08 Sub โฆ 2017 Not โฆ Sub Sโฆ
#> 10 350314047 2019-01-29 15:41:35 Demo 2017 Presโฆ Smallโฆ
#> # โฆ with 145 more rows, and 3 more variables: basic_information <list>,
#> # id <int>, rating <int>
ืืื ืื ื ืืืืจ ืืืืืจืืช ืืช ืืชืืืืช ืืืช ืฉื ืืืื ืืจืืฉืื ืืคื ืืื ืืงืก ืขื ืืื ืฆืืืื ืืชืื ืืจืฉืืื ืืืงืื ื ืช.
ืืืฉื ืฉืืืชืืช ืืืชืจ ืืื ืืืฆืืจ ืืืืืืช ื ืคืจืืืช ืืืื ืืืชืืืืช:
discs %>%
hoist(basic_information, artist = "artists") %>%
select(disc_id = id, artist) %>%
unnest_longer(artist) %>%
unnest_wider(artist)
#> # A tibble: 167 x 8
#> disc_id join name anv tracks role resource_url id
#> <int> <chr> <chr> <chr> <chr> <chr> <chr> <int>
#> 1 7496378 "" Mollot "" "" "" https://api.discogโฆ 4.62e6
#> 2 4490852 "" Una Bรจstiaโฆ "" "" "" https://api.discogโฆ 3.19e6
#> 3 9827276 "" S.H.I.T. (โฆ "" "" "" https://api.discogโฆ 2.77e6
#> 4 9769203 "" Rata Negra "" "" "" https://api.discogโฆ 4.28e6
#> 5 7237138 "" Ivy (18) "" "" "" https://api.discogโฆ 3.60e6
#> 6 13117042 "" Tashme "" "" "" https://api.discogโฆ 5.21e6
#> 7 7113575 "" Desgraciadโฆ "" "" "" https://api.discogโฆ 4.45e6
#> 8 10540713 "" Phantom Heโฆ "" "" "" https://api.discogโฆ 4.27e6
#> 9 11260950 "" Sub Space โฆ "" "" "" https://api.discogโฆ 5.69e6
#> 10 11726853 "" Small Man โฆ "" "" "" https://api.discogโฆ 6.37e6
#> # โฆ with 157 more rows
discs %>%
hoist(basic_information, format = "formats") %>%
select(disc_id = id, format) %>%
unnest_longer(format) %>%
unnest_wider(format) %>%
unnest_longer(descriptions)
#> # A tibble: 280 x 5
#> disc_id descriptions text name qty
#> <int> <chr> <chr> <chr> <chr>
#> 1 7496378 Numbered Black Cassette 1
#> 2 4490852 LP <NA> Vinyl 1
#> 3 9827276 "7"" <NA> Vinyl 1
#> 4 9827276 45 RPM <NA> Vinyl 1
#> 5 9827276 EP <NA> Vinyl 1
#> 6 9769203 LP <NA> Vinyl 1
#> 7 9769203 Album <NA> Vinyl 1
#> 8 7237138 "7"" <NA> Vinyl 1
#> 9 7237138 45 RPM <NA> Vinyl 1
#> 10 13117042 "7"" <NA> Vinyl 1
#> # โฆ with 270 more rows
ืืืืจ ืืื ืชืืื ืืืฆืืจืฃ ืืืืื ืืืืจื ืืืขืจื ืื ืชืื ืื ืืืงืืจื ืืคื ืืฆืืจื.
ืืกืงื ื
ืขื ืืืื ืฉื ืืกืคืจืืื tidyverse
ืืืื ืืืืืืช ืฉืืืืฉืืืช ืจืืืช ืืืืืืืืช ืขื ืืื ืคืืืืกืืคืืืช ืขืืืื ื ืชืื ืื ืืฉืืชืคืช.
ืืืืืจ ืื ืืื ื ืืช ืืฉืคืืช ืืชืคืงืืืื unnest_*()
, ืฉืืืจืชื ืืขืืื ืขื ืืืืืฅ ืืืื ืืื ืืจืฉืืืืช ืืงืื ื ืืช. ืืืืื ืื ืืืืื ืชืืื ืืช ืฉืืืืฉืืืช ืจืืืช ืืืจืืช ืืืงืืืช ืขื ืืืจืช ื ืชืื ืื ืืืชืื ืืงืื ืกืคื ื ืชืื ืื ืืกืืืจืื.
ืืงืืจ: www.habr.com