I have a nested list of the form:
test = {{"sample1", {"elema", "ppm", 238}, {"elemb", "ppm", 57},
{"elemc", "w%", 14.23}, {"elemd", "w%", 0.112}},
{"sample2", {"elema", "ppm", 215}, {"elemb", "ppm", 13},
{"elemc", "w%", 12.13}, {"elemd", "w%", 0.095}},
{"sample3", {"elema", "ppm", 219}, {"elemb", "ppm", 28},
{"elemc", "w%", 19.11}, {"elemd", "w%", 0.55}}};
I want to be able to select and order rows from this list based on another list:
samples = {"sample3", "sample1"};
and reorder elements based on their label,
order = {"elemd","elemc","elemb","elema"};
to end up with something like:
{{0.55, 19.11, 28, 219}, {0.112, 14.23, 57, 238}}
The main aim is to have a robust re-ordering function of the form
trchem[data_, order_, sample_] := ...
I have played around with the following:
Intersection[sample, #] & /@ test
{{"sample1"}, {}, {"sample3"}}
Position[#, test[[All, 1]]] & /@ sample
{{}, {}}
Neither of which are quite right..
I'm sure this is really easy but I can't figure it out at the moment.
Any suggestions? Thanks.