-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcm104.Rmd
80 lines (66 loc) · 1.95 KB
/
cm104.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "Untitled"
author: "Cody"
date: "November 2, 2017"
output: pdf_document
---
## Picking up directly from cm103:
```{r}
library(tidyverse)
library(purrr)
library(repurrrsive)
```
The gh_repos data set is very nested and this makes it difficult to access the varying components.
```{r}
data("gh_repos") #Store the data but as a "promise", meaning R is aware of its presence but its too big
gh_repos #Even writing this will now load the dataset and we see its very big.
View(gh_users) #Need to update r studio, View isn't working
library(listviewer)
jsonedit(gh_repos) #Alternatively
```
Extracting information from lists: Pull from the first level the full names.
```{r}
gh_repos %>%
map_chr(list(1,"full_name"))
```
```{r}
gh_repos %>%
map_int(list(4,"owner","id"))
```
Want to make a named data frame based on pulling entries out of another data frame?
We will take the first repos owner id and create a names vector, put them together to be a two column dataframe
```{r}
library(tibble)
u_id <- gh_repos %>%
map_int(list(1,"owner","id"))
gh_repos_named <- gh_repos %>%
set_names(u_id)
gh_repos_df <- gh_repos_named %>%
enframe("user_id", "repository stuff")
jsonedit(gh_repos_df)
```
Instead we will use logins instead of id
```{r}
u_login <- gh_repos %>%
map_chr(list(1,"owner","login"))
gh_repos_named <- gh_repos %>%
set_names(u_login)
gh_repos_df <- gh_repos_named %>%
enframe("user_login", "other repository stuff")
jsonedit(gh_repos_df)
```
```{r}
gh_repos_df %>%
filter(user_login %in% c("masalmon", "leeper")) %>%
mutate(number_of_repositories=map_int(`other repository stuff`,length)) %>%
jsonedit()
```
Put together the aliases and the names of each character on GoT
```{r}
aliases_names <- set_names(map(got_chars,"aliases"),map(got_chars,"name"))
map_int(aliases_names,length) #Lol Dany has 11 names
collapse_by_comma <- function(vec_of_strings){
paste(vec_of_strings,collapse = ", ")
}
map(aliases_names,collapse_by_comma)
```