1/31/23
mutate()
filter()
ggplot(data, aes())
+
Factors: factor(variable, levels = c(...), labels = c(...))
Logical Data: TRUE
or FALSE
Remove missing data with na.rm = TRUE
arugment
Categorical | Numeric | |
---|---|---|
Categorical |
|
|
Numeric |
|
ifelse()
function
ifelse(condition, output, output2)
df <- df %>%
mutate(nocturnal = ifelse(lubridate::hour(Timestamp)<12,
"morning person",
"nocturnal"))
df$nocturnal
[1] "morning person" "morning person" "morning person" "morning person"
[5] "nocturnal" "nocturnal" "nocturnal" "morning person"
[9] "morning person" "morning person" "morning person" "morning person"
[13] "nocturnal"
x&y
checks whether both x AND y are TRUEx|y
checks whether either x OR y is TRUEdf <- df %>%
mutate(nocturnal_coder = ifelse(
lubridate::hour(Timestamp)<12&code_experience=="Yes",
"Not Nocturnal Coder",
"Nocturnal Coder"))
df$nocturnal_coder[1:7]
[1] "Nocturnal Coder" "Not Nocturnal Coder" "Nocturnal Coder"
[4] "Not Nocturnal Coder" "Nocturnal Coder" "Nocturnal Coder"
[7] "Nocturnal Coder"
TRUE
!condition
means NOT conditioncase_when()
: tidyverse function to check multiple conditions sequentiallydf <- df %>%
mutate(code_interests =
case_when(code_experience=="Yes"&american_pol==1~"AP Coder",
code_experience=="Yes"&comparative_pol==1~"CP Coder",
code_experience=="Yes"&international_rel==1~"IR Coder",
T~"Other"))
df$code_interests
[1] "Other" "CP Coder" "Other" "AP Coder" "AP Coder" "AP Coder"
[7] "Other" "Other" "AP Coder" "AP Coder" "Other" "AP Coder"
[13] "Other"
select()
# A tibble: 2 × 2
year python_exp
<chr> <dbl>
1 Junior 0
2 Sophomore 1
dplyr
functionsdata
tabDownload Data
party_code
variable, so it reads “D”, “R” instead of “100”, “200”party_code
variable, so it reads “D”, “R” instead of “100”, “200”party_code
variable, so it reads “D”, “R” instead of “100”, “200”nominate_dim1
datasummary_skim()
to summarize the numeric variables
modelsummary
packagenominate_dim1
datasummary
to summarize nominate_dim1
and nominate_dim2
modelsummary
packagenominate_dim1
filled by partynominate_dim2
against nominate_dim1
nominate_dim2
against nominate_dim1
group_by()
function in tidyverse
to group our data by given variablessummarize()
and desired function to create new function
mutate()
nominate_dim1
by Congress and party?
Summarizing Data