3
$\begingroup$

Given a data set how to assign definitions to the subsets. For instance given the data

data = {{0, 1, 1}, {0, 1, 1}, {1, 1, 0}, {0, 1, 1}, {1, 1, 0}}

if {0, 1, 1} is SetA and {1, 1, 0} is SetB the result would be data={SetA, SetA, SetA, SetB, SetA}

$\endgroup$

1 Answer 1

1
$\begingroup$

You can use ReplaceAll:

rules = {{0, 1, 1} -> setA, {1, 1, 0} -> setB};

data /. rules
{setA, setA, setB, setA, setB}

Alternatively, define a function that evaluates to setA for {0,1,1} and to setB for {1,1,0} and map it on data:

ClearAll[f]
f[{0, 1, 1}] = setA;
f[{1, 1, 0}] = setB;

f /@ data
{setA, setA, setB, setA, setB}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.