Skip to content

Commit

Permalink
replaced ifelse with fcase in map_prob_change()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbaazam committed May 4, 2023
1 parent 0023aba commit 6d1eccc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ make_conf <- function(value, CrI = 90, reverse = FALSE) {
#' "Likely decreasing" (< 0.95), "Decreasing" (<= 1)
#' @param var Numeric variable to be categorised
#'
#' @importFrom data.table fcase
#' @return A character variable.
#' @export
#' @examples
Expand All @@ -85,17 +86,15 @@ make_conf <- function(value, CrI = 90, reverse = FALSE) {
#'
#' map_prob_change(var)
map_prob_change <- function(var) {
# nolint start
var <- ifelse(var < 0.05, "Increasing",
ifelse(var < 0.4, "Likely increasing",
ifelse(var < 0.6, "Stable",
ifelse(var < 0.95, "Likely decreasing",
"Decreasing"
)
)
)
)
# nolint end

var <- data.table::fcase(
var < 0.05, "Increasing",
var >= 0.05 & var < 0.4, "Likely increasing",
var >= 0.4 & var < 0.6, "Stable",
var >= 0.6 & var < 0.95, "Likely decreasing",
var >= 0.95 & var <= 1, "Decreasing"
)

var <- factor(var, levels = c(
"Increasing", "Likely increasing", "Stable",
"Likely decreasing", "Decreasing"
Expand Down

0 comments on commit 6d1eccc

Please sign in to comment.