Some tidyverse commands I came across and hadn’t seen before. Thought it would be useful to store them here.
Replace missing values with the median.
Change a variable’s label.
df <- df %>%
mutate(group = replace(group, group == "A", "Group-A"))
Recode is a simple version of case_when
.
df %>%
mutate(color = recode(color,
"g" = "green",
"b" = "blue",
"y" = "y",
.default = "other"))
calc <- function(data, group_var) {
data %>%
group_by({{ group_var }}) %>%
summarize(mean = mean(stress))
}
df %>%
select_if(is.numeric) %>%
select_if(~mean(., na.rm=TRUE) > 10)
df %>%
select_all(any_vars(str_detect(., pattern = "Mu")))
mutate_if(is.numeric)
mutate_at(vars(contains("Q")))
Bo\(^2\)m =)