Question

I was given four bars of printed ink. I measured all four bars and got what the color components of each are. I'm trying to determine and show whether the gray bars being between the target values indicates that the solid bars are going to be in spec. The given is that the gray bar is between target values. If it is not, then I want to remove the corresponding values for that sample/zone/color. Here is a snippet of the data:

rm(list = ls())
library(data.table)

testDT <- data.table(structure(list(Zone = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,8L, 8L, 8L, 8L, 8L, 8L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,8L, 8L, 8L, 8L, 8L, 8L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,8L, 8L, 8L, 8L, 8L, 8L),
                                    Data = c(0.62, 0.27, 0.35, 0.95, 0.62,0.26, 0.35, 0.95, 0.64, 0.27, 0.36, 0.96, 0.64, 0.27, 0.37, 0.95,0.64, 0.27, 0.38, 0.96, 0.64, 0.27, 0.38, 0.96, 0.65, 0.27, 0.38,0.99, 0.68, 0.27, 0.38, 0.99, 0.61, 0.3, 0.91, 0.51, 0.61, 0.3,0.91, 0.51, 0.63, 0.3, 0.93, 0.52, 0.63, 0.3, 0.94, 0.52, 0.66,0.3, 0.97, 0.52, 0.67, 0.3, 0.99, 0.52, 0.66, 0.29, 0.99, 0.54,0.67, 0.29, 1.01, 0.54, 0.61, 0.79, 0.69, 0.37, 0.61, 0.79, 0.7,0.37, 0.62, 0.78, 0.71, 0.38, 0.62, 0.79, 0.72, 0.38, 0.63, 0.75,0.75, 0.38, 0.63, 0.76, 0.76, 0.38, 0.62, 0.72, 0.76, 0.39, 0.63,0.73, 0.78, 0.39),
                                    Bar = structure(c(2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L,3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 3L, 1L),
                                        .Label = c("Cyan", "Gray","Magenta", "Yellow"), class = "factor"), SampleID = c(6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L,6L, 6L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L),
                                    Color = structure(c(1L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L),
                                        .Label = c("Cyan","Magenta", "Yellow"), class = "factor")), .Names = c("Zone","Data", "Bar", "SampleID", "Color"), sorted = "Color", class = c("data.table","data.frame"), row.names = c(NA, -96L)), key='Color') 

The target values for the gray bars are 0.55 to 0.65. Basically, I just want to remove the data from the solid bars that correspond to data not in the target for the gray bars by zone.

So my approach is that I'll first find out which sample, zone, and colors do fall between the values for the gray bar. That code is as follows:

testDT2 <- testDT[Bar == "Gray"]
testDT2 <- testDT2[Color != "Visual"]
ranges <- data.table(Color = c("Cyan","Magenta","Yellow"), low  = c(0.55,0.55,0.55), high = c(0.65,0.65,0.65)); ranges
`%okDen%` <- function(x = test, vals1 = low, vals2 = high) x >= vals1 & x <= vals2
`%NotOkDen%` <- Negate(`%okDen%`)
setkeyv(ranges,'Color'); setkeyv(testDT2,'Color')
testDT2 <- merge(testDT2, ranges, all.x = TRUE); testDT2
testDT2 <- testDT2[`%NotOkDen%`(Data, low, high), Data := NA]

testDT1 <- testDT[Bar != "Gray"]
testDT1 <- testDT1[Color != "Visual"]

Now, I need to create a function that will cherry pick the values that are now NA’s and remove the corresponding values from the colored bar data.

For example: Gray bar sample 7, zone 8 for cyan is not within the required values and is thus given an NA. I want to create a function to see that and then go find the data for the cyan bar, cyan color, for sample 7 in zone 8 and list it as NA.

Would anyone be able to help me create such a function? I have no idea where to go.

Was it helpful?

Solution

All credit for this goes to @Arun.

testDT[testDT[, .I[Data[Bar == "Gray"] %between% c(0.55, 0.65)], list(Zone, SampleID, Color)]$V1]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top