0
$\begingroup$

I have a dataset in form of {{typ1,typ2,typ3..typ15},.....{typ1,typ2,typ3,...typ15}}. The attached image shows the table form of data. I want to select any 3 column of the data and do some calculation on selected columns, for example (type1, type2,type3) or (type8, type12,type15). What I need, is to give the user ability to select the desired 3 columns and then do the calculation some how to manipulate the selection at begging. Thank you for your help. enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ The question you have posed is unclear. (1) Manipulate has a special meaning in Mathematica. (2) Dataset is a reserved word and is different from List. (3) " What I need, is to give the user ability to select ..." : It is not clear whether you want a GUI or want to use simple commands such as Part. (4) What do you mean by "manipulate the selection at begging" ? You can include the data you have shown as a picture using copy-paste directly from the input cell and then rephrase and edit your question to make it more clear. Thanks. $\endgroup$
    – Syed
    Feb 1, 2022 at 6:22
  • $\begingroup$ A more idiomatic use of Dataset (with rows of data, i.e. the Transpose of your data): ds = AssociationThread["Type" <> ToString[#] & /@ Range@15, RandomReal[1, {15, 30}]] // Dataset; -- Select three rows and apply a function to them individually: ds[{"Type8", "Type12", "Type15"}, Mean] -- Multiply three rows: Normal@ds[#Type8 * #Type12 * #Type15 &]` $\endgroup$
    – Michael E2
    Feb 1, 2022 at 18:11

1 Answer 1

3
$\begingroup$

First we need some data set:

SeedRandom[1];
data = RandomInteger[{0, 9}, {10, 5}];
header = Table["Type" <> ToString[i], {i, 5}];
ds = (<|Thread[header -> #]|>) & /@ data  // Dataset

enter image description here

Then assume the user made some selection of columns:

selection = {2, 3};
t1 = ds[[All, selection]]

enter image description here

To add the second column to the third one:

t2 = t1[Values]
t2[All, Total]

enter image description here

To multiply column 2 and 3:

t2[All, Times @@ # &]

enter image description here

$\endgroup$

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