-
Notifications
You must be signed in to change notification settings - Fork 3
/
getProportionLow.R
28 lines (28 loc) · 955 Bytes
/
getProportionLow.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' Get proportion of Low genetic value animals
#'
## Copyright(c) 2017-2020 R. Mark Sharp
## This file is part of nprcgenekeepr
#'
#' @return List of the proportion of Low genetic value animals and the
#' dashboard color to be assigned base on that proportion.
#'
#' @param geneticValues character vector of the genetic values. This vector
#' is to have already been filtered to remove animals that should not be
#' included in the calculation.
#' @importFrom stringi stri_detect_fixed
getProportionLow <- function(geneticValues) {
proportion <-
length(geneticValues[stri_detect_fixed(geneticValues, "Low")]) /
length(geneticValues)
if (proportion > 0.5) {
color <- "red"
colorIndex <- 1
} else if (proportion <= 0.5 & proportion >= 0.3) {
color <- "yellow"
colorIndex <- 2
}else if (proportion < 0.3) {
color <- "green"
colorIndex <- 3
}
list(proportion = proportion, color = color, colorIndex = colorIndex)
}