I need to filter data and create a new column OutOfSpec based on dynamic input selected from a selectInput widget as follows:
mutate(OutOfSpec = ifelse(Assayperc < (AssaypercLL %in% input$assayCountry)| Assayperc > (AssaypercUL %in% input$assayCountry), BatchNumber, ""))
Is the above right as I seem to be getting weird results which is opposite of the expected as all data is being labelled as out of specification. assayCountry is a selectInput of the ActiveIngredient column. So basically, I need this code to pick up the corresponding AssaypercLL and the AssaypercUL and compare to the Assayperc. If the Assayperc is outside the AssayperLL and AssaypercUL, then the BatchNumber is annotated to the created OutOfSpec column. Thank you Please assist.
The data is as follows:
structure(list(ï..ActiveIngredient = structure(c(2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("Caridone",
"Entepronone"), class = "factor"), Assay = c(94.9, 94.9, 94.9,
94.9, 94.9, 94.9, 101.6, 101.6, 101.6, 101.6, 101.6, 101.6, 95,
95, 95, 95, 95, 95, 100.2, 100.2, 100.2, 100.2, 100.2, 100.2,
96.4, 96.4, 96.4, 96.4, 96.4, 96.4, 100.6, 100.6, 100.6, 100.6,
100.6, 100.6, 93.7, 93.7, 93.7, 93.7, 93.7, 93.7, 101.8, 101.8,
101.8, 101.8, 101.8, 101.8, 90.5, 90.5, 90.5, 90.5, 90.5, 90.5,
101.4, 101.4, 101.4, 101.4, 101.4, 101.4, 91, 91, 91, 91, 91,
91, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 92.6, 92.6, 92.6, 92.6,
92.6, 92.6, 93.5, 93.5, 93.5, 93.5, 93.5, 93.5, 94, 94, 94, 94,
94, 94, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 98.6), Assayperc = c(0.949,
0.949, 0.949, 0.949, 0.949, 0.949, 1.016, 1.016, 1.016, 1.016,
1.016, 1.016, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 1.002, 1.002,
1.002, 1.002, 1.002, 1.002, 0.965, 0.965, 0.965, 0.965, 0.965,
0.965, 1.006, 1.006, 1.006, 1.006, 1.006, 1.006, 0.937, 0.937,
0.937, 0.937, 0.937, 0.937, 1.018, 1.018, 1.018, 1.018, 1.018,
1.018, 0.905, 0.905, 0.905, 0.905, 0.905, 0.905, 1.014, 1.014,
1.014, 1.014, 1.014, 1.014, 0.91, 0.91, 0.91, 0.91, 0.91, 0.91,
0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.926, 0.926, 0.926,
0.926, 0.926, 0.926, 0.935, 0.935, 0.935, 0.935, 0.935, 0.935,
0.94, 0.94, 0.94, 0.94, 0.94, 0.94, 0.957, 0.957, 0.957, 0.957,
0.957, 0.957, 0.986), AssayLL = c(90L, 90L, 90L, 90L, 90L, 90L,
93L, 93L, 93L, 93L, 93L, 93L, 90L, 90L, 90L, 90L, 90L, 90L, 93L,
93L, 93L, 93L, 93L, 93L, 90L, 90L, 90L, 90L, 90L, 90L, 93L, 93L,
93L, 93L, 93L, 93L, 90L, 90L, 90L, 90L, 90L, 90L, 93L, 93L, 93L,
93L, 93L, 93L, 90L, 90L, 90L, 90L, 90L, 90L, 93L, 93L, 93L, 93L,
93L, 93L, 90L, 90L, 90L, 90L, 90L, 90L, 93L, 93L, 93L, 93L, 93L,
93L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L,
90L, 90L, 90L, 90L, 90L, 90L, 93L, 93L, 93L, 93L, 93L, 93L, 93L
), AssaypercLL = c(0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9,
0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.93, 0.93,
0.93, 0.93, 0.93, 0.93, 0.93), AssayUL = c(110L, 110L, 110L,
110L, 110L, 110L, 107L, 107L, 107L, 107L, 107L, 107L, 110L, 110L,
110L, 110L, 110L, 110L, 107L, 107L, 107L, 107L, 107L, 107L, 110L,
110L, 110L, 110L, 110L, 110L, 107L, 107L, 107L, 107L, 107L, 107L,
110L, 110L, 110L, 110L, 110L, 110L, 107L, 107L, 107L, 107L, 107L,
107L, 110L, 110L, 110L, 110L, 110L, 110L, 107L, 107L, 107L, 107L,
107L, 107L, 110L, 110L, 110L, 110L, 110L, 110L, 107L, 107L, 107L,
107L, 107L, 107L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 107L,
107L, 107L, 107L, 107L, 107L, 107L), AssaypercUL = c(1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.07, 1.07, 1.07, 1.07, 1.07, 1.07,
1.07), BatchNumber = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 2L, 2L, 2L, 2L, 2L), levels = c("170722",
"17095", "180301", "180702", "ACO36", "CUJ108004", "FN7001"), class = "factor")), class = "data.frame", row.names = c(NA,
-97L))