You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tidy <- data %>%
dplyr::group_by(dplyr::across(c({{cols}}, {{rows}})), .drop = FALSE) %>%
dplyr::summarize(value = dplyr::n()) %>%
# tidyr::complete(dplyr::across(c({{cols}}, {{rows}}))) %>% # <- It would be nice if this bit worked but across only works in dplyr verbs. complete is tidyr verb
dplyr::mutate(value = tidyr::replace_na(.data$value, 0)) %>%
dplyr::arrange(dplyr::across(c({{rows}}, {{cols}}))) %>%
dplyr::ungroup()
do not pivot if argument pivot false or no columns specified
pivot_count <- function(data, cols = NULL, rows = NULL, pivot = T){
cols_quo <- rlang::enquo(cols)
tidy <- data %>%
dplyr::group_by(dplyr::across(c({{cols}}, {{rows}})), .drop = FALSE) %>%
dplyr::summarize(value = dplyr::n()) %>%
# tidyr::complete(dplyr::across(c({{cols}}, {{rows}}))) %>% # <- It would be nice if this bit worked but across only works in dplyr verbs. complete is tidyr verb
dplyr::mutate(value = tidyr::replace_na(.data$value, 0)) %>%
dplyr::arrange(dplyr::across(c({{rows}}, {{cols}}))) %>%
dplyr::ungroup()
do not pivot if argument pivot false or no columns specified
if(pivot == F | rlang::quo_is_null(cols_quo)){
otherwise pivot by columns
}else{
tidy %>%
tidyr::pivot_wider(names_from = {{cols}})
}
}
The text was updated successfully, but these errors were encountered: