-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecture6.R
77 lines (55 loc) · 1.2 KB
/
lecture6.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
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
# install.packages("andrew-griffen/gdata")
# install.packages("andrew-griffen/griffen")
library(devtools)
library(tidyverse)
library(griffen)
library(gdata)
library(stringi)
x <- c("a","b","c")
x <- factor(x)
x[1:2]
x <- c("a","b","c")
x <- factor(x, level = c("a","b","c"))
x <- c("a","b","c")
x <- factor(x, level = c("a","b","c","d"))
punc <- c(".",","," ")
g <-
gettysburg |>
stri_replace_all_fixed(punc, "", vectorize_all = FALSE)
g <-
g |>
str_split("") |>
unlist() |>
tolower()
g_df = tibble(g)
g_df <-
g_df |>
mutate(g = factor(g))
g_df_pct <-
g_df |>
group_by(g) |>
pct()
g_df <-
g_df |>
mutate(g = factor(g, levels = rev(letters)))
g_df_pct <-
g_df |>
group_by(g, .drop = FALSE) |>
pct()
ggplot(g_df_pct, aes(pct,g)) + geom_point()
left_join(x,y)
x |> left_join(y)
inner_join(x,y)
right_join(x,y)
cps |>
group_by(year,state) |>
summarise(mean_wage = mean(wage)) |>
right_join(cps) |>
left(year,state,mean_wage,wage)
anti_join(x,y)
full_join(x,y)
cps <- cps |> left_join(state_population)
anti_join(cps,state_population)
tbl1 |> pivot_longer(-id)
tbl4 |> pivot_longer(cols = starts_with("contribution"))
tbl4 |> pivot_longer(contains("contribution"))