-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.R
46 lines (37 loc) · 1.1 KB
/
Table.R
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
# import US murders data
library(tidyverse)
library(ggrepel)
library(dslabs)
ds_theme_set()
data(murders)
head(murders)
# make two smaller tables to demonstrate joins
tab1 <- slice(murders, 1:5) %>% select(state, population)
tab1
tab2 <- slice(results_us_election_2016, c(1:3, 5, 7:8)) %>% select(state, electoral_votes)
tab2
dat <- left_join(tab1, tab2, by = "state")
dat
library(Lahman)
top <- Batting %>%
filter(yearID == 2016) %>%
arrange(desc(HR)) %>% # arrange by descending HR count
slice(1:10) # take entries 1-10
top %>% as_tibble()
People %>% as_tibble()
head(People)
top_names <- top %>% left_join(People) %>%
select(playerID, nameFirst, nameLast, HR)
top_names
top_salary <- Salaries %>% filter(yearID == 2016) %>%
anti_join(top_names) %>%
select(nameFirst, nameLast, teamID, HR, salary)
top_salary
top <- AwardsPlayers %>%
filter(yearID == 2016) %>%
slice(1:10) # take entries 1-10
top
# solution 1
Awards_2016 <- AwardsPlayers %>% filter(yearID == 2016)
length(intersect(Awards_2016$playerID, top_names$playerID))
length(setdiff(Awards_2016$playerID, top_names$playerID))