Hello,
I am cleaning a data table of chemical contaminants found in food samples, in which are found four variables:
1. Batch (denoting the batch in which samples were processed)
2. Food
3. Analyte (containing the names of various molecular compounds)
4. Quantity (containing the quantity detected by a laboratory)
In some cases, the chemical compound is found in several different isomers (molecular variations). For example:
Batch Food Analyte Quantity
1 apples a-BHC 0.1
1 apples b-BHC 0.1
1 apples g-BHC 0.1
1 apples DDT 0.7
2 oranges DIE 0.4
3 pineapples PCL 0.6
I am seeking advice on how to combine the quantities of related isomers (a-BHC, b-BHC, g-BHC) into a new field "BHC (all forms)", within unique batch/food subsets. In this table example, that would be (batch==1 & food==apples).
I can specify isomer sets (there are only a few), but am hoping to avoid manual search errors by a loop that can look for pre-specified isomer sets within any unique batch/food subsets (of which there are many).
There are 6210 observations, so I am hoping to find a way to automate this process within a loop, with the resulting table looking like this.
Batch Food Analyte Quantity
1 Apples BHC (all forms) 0.3
1 apples DDT 0.7
2 oranges DIE 0.4
3 pineapples PCL 0.6
Any guidance would be appreciated!
I am cleaning a data table of chemical contaminants found in food samples, in which are found four variables:
1. Batch (denoting the batch in which samples were processed)
2. Food
3. Analyte (containing the names of various molecular compounds)
4. Quantity (containing the quantity detected by a laboratory)
In some cases, the chemical compound is found in several different isomers (molecular variations). For example:
Batch Food Analyte Quantity
1 apples a-BHC 0.1
1 apples b-BHC 0.1
1 apples g-BHC 0.1
1 apples DDT 0.7
2 oranges DIE 0.4
3 pineapples PCL 0.6
I am seeking advice on how to combine the quantities of related isomers (a-BHC, b-BHC, g-BHC) into a new field "BHC (all forms)", within unique batch/food subsets. In this table example, that would be (batch==1 & food==apples).
I can specify isomer sets (there are only a few), but am hoping to avoid manual search errors by a loop that can look for pre-specified isomer sets within any unique batch/food subsets (of which there are many).
There are 6210 observations, so I am hoping to find a way to automate this process within a loop, with the resulting table looking like this.
Batch Food Analyte Quantity
1 Apples BHC (all forms) 0.3
1 apples DDT 0.7
2 oranges DIE 0.4
3 pineapples PCL 0.6
Any guidance would be appreciated!
Comment