I have created a data.table that looks, for example as the following:
a b c exposure
1 2 3 0.5
1 2 3 0.5
4 5 6 0.75
4 5 6 0.25
I am summing the values in the exposure column by unique combinations of a, b, and c variables. Using data.table, my command is
data1 <- data[, .(final = sum(exposure)), by = list(a, b, c)]
As expected, this results in:
a b c final
1 2 3 1
4 5 6 1
However, when I try to retrieve the unique values using
unique(data1$final)
I get: 1 1
I have tried using str and class to see if the 1s are different data types, but they are both numeric. When I try
unique(data1$final) == c(1,1) ## the result is TRUE FALSE
Do you have any suggestions on how to debug this, or why unique is returning of the same value? Ideally I am trying to create a check that says there is only one unique value (equal to 1) of the summed rows.