data = Dataset[{<|"userId" -> 5324,
"PerfFreeResponse" -> 0.8181818181818182`,
"PerfMultipleChoice" -> 0.5`, "PerfSingleChoice" -> 0.5`,
"PerfWriteCode" -> 1.`, "MinPerf" -> 0.5`|>, <|"userId" -> 5325,
"PerfFreeResponse" -> 1.`, "PerfMultipleChoice" -> 1.`,
"PerfSingleChoice" -> 1.`, "PerfWriteCode" -> 1.`,
"MinPerf" -> 1.`|>, <|"userId" -> 5326,
"PerfFreeResponse" -> 0.9090909090909091`,
"PerfMultipleChoice" -> 0.6666666666666666`,
"PerfSingleChoice" -> 1.`, "PerfWriteCode" -> 1.`,
"MinPerf" -> 0.6666666666666666`|>, <|"userId" -> 5330,
"PerfFreeResponse" -> 0.6363636363636364`,
"PerfMultipleChoice" -> 0.6666666666666666`,
"PerfSingleChoice" -> 1.`, "PerfWriteCode" -> 1.`,
"MinPerf" -> 0.6363636363636364`|>, <|"userId" -> 5331,
"PerfFreeResponse" -> 0.6363636363636364`,
"PerfMultipleChoice" -> 1.`, "PerfSingleChoice" -> 1.`,
"PerfWriteCode" -> 0.`, "MinPerf" -> 0.`|>}]
I want to append another column which tells me which type of question (Free response, Multiple Choice, Single Choice, write Code) has the minimum score. I wrote the following code for that:
data[All, Append[#, "MinPerfType" ->
If[#MinPerf == 1., "Excellent Performance",
If[#MinPerf == #PerfFreeResponse, "Free Response",
If[#MinPerf == #PerfMultipleChoice, "Multiple Choice",
If[#MinPerf == #PerfSingleChoice, "Single Choice",
If[#MinPerf == #PerfWriteCode, "Write Code", "Blah"]]]]]] &]
But the problem with this code is, if two columns show the MinPerf (except when MinPerf==1.), it gives me the name of only one column and not both of them. Eg., the first row of data shows MinPerf = 0.5, which is true for both Multiple Choice and Single Choice. In that case, I want MinPerfType to show both Multiple Choice and Single Choice and not just either one of them.
Which
to handle the cascading conditions. Also, wouldn'tMinimalBy
be useful for this?MinimalBy[assoc, Identity]
returns an association containing all keys that have minimal values. $\endgroup$ – Sjoerd Smit May 1 '19 at 13:22data[All, Append[#, "MinPerfType" -> If[#MinPerf == 1., "Excellent Perf", MinimalBy[{#PerfFreeResponse, #PerfMultipleChoice, \ #PerfSingleChoice, #PerfWriteCode}, #MinPerf]]] &]
. But I need names corresponding to the columns that have the minimum score. MinimalBy satisfies the condition of giving two minimum values but not the corresponding names $\endgroup$ – Priyesh Sharma May 1 '19 at 13:30Keys @ MinimalBy[KeyDrop[#, {"userId", "MinPerf"}], Identity]
? $\endgroup$ – Sjoerd Smit May 1 '19 at 13:35