diff --git a/DESCRIPTION b/DESCRIPTION index c5c46bd..444ef2d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: CodeAndRoll2 Title: CodeAndRoll2 for vector, matrix and list manipulations -Version: 2.8.19 +Version: 2.8.20 Authors@R: person("Abel", "Vertesy", , "av@imba.oeaw.ac.at", role = c("aut", "cre")) Description: CodeAndRoll2 is a set of more than 170 productivity functions diff --git a/Development/config.R b/Development/config.R index 5cd2eeb..8b1745c 100644 --- a/Development/config.R +++ b/Development/config.R @@ -3,7 +3,7 @@ DESCRIPTION <- list( package.name = "CodeAndRoll2", - version = "2.8.19", + version = "2.8.20", title = "CodeAndRoll2 for vector, matrix and list manipulations", description = "CodeAndRoll2 is a set of more than 170 productivity functions for vector, matrix and list manipulations and math. Used by MarkdownReports, ggExpress, SeuratUtils, etc.", diff --git a/R/CodeAndRoll2.R b/R/CodeAndRoll2.R index 3663123..5af93c3 100644 --- a/R/CodeAndRoll2.R +++ b/R/CodeAndRoll2.R @@ -1274,8 +1274,14 @@ translate <- function(vec, old, new) { #' @param upto max, Default: 100 #' @export rescale <- function(vec, from = 0, upto = 100) { - vec <- vec - min(vec, na.rm = TRUE) - vec <- vec * ((upto - from) / max(vec, na.rm = TRUE)) + vmin <- min(vec, na.rm = TRUE) + vmax <- max(vec, na.rm = TRUE) + if (vmax == vmin) { + vec[!is.na(vec)] <- from + (upto - from) / 2 + return(vec) + } + vec <- vec - vmin + vec <- vec * ((upto - from) / (vmax - vmin)) vec <- vec + from return(vec) } # fun