The simplifyTreatment function is designed to handle and simplify
a treatment vector, which can be either a factor or a character vector.
The primary goal of this function is to resolve issues with numeric
precision that often arise in Excel datasheets, such as numbers
being represented with excessive decimal places, like 12.300000000000001
or 8.3579999999999.
Examples
x <- structure(c(
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L
), levels = c(
"Control", "1", "3.51", "12.300000000000001",
"42.9", "150"
), class = "factor")
simplifyTreatment(x)
#> [1] Control Control Control Control Control Control 1 1 1
#> [10] 1 3.51 3.51 3.51 3.51 12.3 12.3 12.3 12.3
#> [19] 42.9 42.9 42.9 42.9 150 150 150 150 Control
#> [28] Control Control Control Control Control 1 1 1 1
#> [37] 3.51 3.51 3.51 3.51 12.3 12.3 12.3 12.3 42.9
#> [46] 42.9 42.9 42.9 150 150 150 150 Control Control
#> [55] Control Control Control Control 1 1 1 1 3.51
#> [64] 3.51 3.51 3.51 12.3 12.3 12.3 12.3 42.9 42.9
#> [73] 42.9 42.9 150 150 150 150
#> Levels: Control 1 3.51 12.3 42.9 150