Skip to content

Commit

Permalink
account for non-numeric grades
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Oct 19, 2022
1 parent f723983 commit e1a6a72
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ s_count_occurrences_by_grade <- function(df,
if (!is.ordered(grade)) {
grade_lbl <- obj_label(grade)
lvls <- levels(grade)
lvls[!grepl("^\\d+$", lvls)] <- min(as.numeric(lvls[grepl("^\\d+$", lvls)])) - 1
lvl_ord <- levels(grade)[order(as.numeric(lvls))]
if (sum(grepl("^\\d+$", lvls)) %in% c(0, length(lvls))) {
lvl_ord <- lvls
} else {
lvls[!grepl("^\\d+$", lvls)] <- min(as.numeric(lvls[grepl("^\\d+$", lvls)])) - 1
lvl_ord <- levels(grade)[order(as.numeric(lvls))]
}
grade <- formatters::with_label(factor(grade, levels = lvl_ord, ordered = TRUE), grade_lbl)
}

Expand Down

0 comments on commit e1a6a72

Please sign in to comment.