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.
1 Answer
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
Then assume the user made some selection of columns:
selection = {2, 3};
t1 = ds[[All, selection]]
To add the second column to the third one:
t2 = t1[Values]
t2[All, Total]
To multiply column 2 and 3:
t2[All, Times @@ # &]
Manipulate
has a special meaning in Mathematica. (2)Dataset
is a reserved word and is different fromList
. (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 asPart
. (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$Dataset
(with rows of data, i.e. theTranspose
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$