-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecture5.R
104 lines (76 loc) · 1.53 KB
/
lecture5.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# install.packages("stringi")
library(devtools)
library(tidyverse)
library(griffen)
library(gdata)
library(stringi)
cps |>
select(year) |>
distinct() |>
arrange(year)
cps |>
select(year) |>
arrange(year) |>
distinct()
cps |>
select(year) |>
distinct() |>
arrange(-year)
cps |>
select(year) |>
distinct() |>
arrange(-year) |>
pull()
cps |>
select(year) |>
distinct() |>
arrange(year) |>
print_all()
filter(cps, year == 1999)
cps |>
filter(year == 1999)
cps |>
filter(educ_years < 12)
cps |>
filter(educ_years > 16 & state == "Kentucky")
cps |>
filter(educ_years > 16 | state == "Kentucky")
cps |> filter(year == 1984 | year == 1999)
cps |> filter(year %in% c(1999,1984))
cps <- cps |> rename(area = region)
cps |>
filter(year == 1999) |>
select(wage) |>
pull() |>
mean()
cps <-
cps |>
mutate(log_wage = log(wage))
cps <-
cps |>
mutate(earnings = hours_lastweek * wage)
cps <-
cps |>
mutate(year_of_birth = 2024 - age)
cps <-
cps |>
mutate(if_kentucky = if_else(state == "Kentucky",1,0))
cps |>
group_by(education_category) |>
summarise(mean_wage = mean(wage))
cps |>
group_by(year) |>
summarise(mean_wage = mean(wage))
cps |>
group_by(education_category,year) |>
summarise(mean_wage = mean(wage))
cps_sd <-
cps |>
group_by(year) |>
summarise(sd_wage = sd(wage, na.rm = TRUE))
ggplot(data = cps_sd, aes(x = year, y = sd_wage)) + geom_point()
cps |>
group_by(year) |>
summarise(across(c(black,white,married),mean))
cps |>
select(where(is.character))