I have a dataset that has employees' capacity each month, and I want to get a total for each employee across all months:
library(dplyr)
data <- tibble(employee = c("Justin", "Corey","Sibley", "Justin", "Corey","Sibley"),
education = c("graudate", "student", "student", "graudate", "student", "student"),
fte_max_capacity = c(1, 2, 3, 1, 2, 3),
project = c("big", "medium", "small", "medium", "small", "small"),
aug_2021 = c(1, 1, 1, 1, 1, 1),
sep_2021 = c(1, 1, 1, 1, 1, 1),
oct_2021 = c(1, 1, 1, 1, 1, 1),
nov_2021 = c(1, 1, 1, 1, 1, 1))
I've tried following using the code found here, but I get this error:
data %>%
dplyr::select(-contains("project")) %>%
dplyr::group_by(employee) %>%
mutate(sum = rowSums(select(., vars(contains("_20")))))
Error: Problem with `mutate()` input `sum`.
x Must subset columns with a valid subscript vector.
x Subscript has the wrong type `quosures`.
ℹ It must be numeric or character.
ℹ Input `sum` is `rowSums(select(., vars(contains("_20"))))`.
ℹ The error occurred in group 1: employee = "Corey".
I also tried this a modified version of the solution from this website. But I also get an error, despite all the relevant columns being numeric:
data %>%
dplyr::select(-contains("project")) %>%
dplyr::group_by(employee) %>%
mutate_at(vars(contains("_20"), rowSums(., na.rm = T)))
Error: 'x' must be numeric