Qurak

Perform operations on subgroups of data

Anleitung 14 Schritte, der Reihe nach in einer Sitzung ausgeführt. Jeder Schritt wurde gegen die Engine ausgeführt, und die Ausgabe unten ist, was er erzeugte.

Schritt 1
agdata = {{clay, seedB, 175}, {silty, seedB, 180}, {clay, seedB, 165}, {sandy, seedA, 168}, {clay, seedA, 184}, {sandy, seedB, 171}, {sandy, seedB, 173}, {sandy, seedA, 189}, {clay, seedA, 186}, {silty, seedB, 174}, {clay, seedA, 192}, {clay, seedA, 184}, {clay, seedA, 179}, {sandy, seedA, 182}, {sandy, seedB, 177}, {silty, seedA, 180}, {clay, seedB, 175}, {silty, seedB, 181}, {sandy, seedA, 176}, {silty, seedB, 190}};

Keine Ausgabe - dieser Schritt bereitet etwas für den nächsten vor.

Schritt 2
bySoilType = GatherBy[agdata, First]
Ausgabe
{{{clay, seedB, 175}, {clay, seedB, 165}, {clay, seedA, 184}, {clay, seedA, 186}, {clay, seedA, 192}, {clay, seedA, 184}, {clay, seedA, 179}, {clay, seedB, 175}}, {{silty, seedB, 180}, {silty, seedB, 174}, {silty, seedA, 180}, {silty, seedB, 181}, {silty, seedB, 190}}, {{sandy, seedA, 168}, {sandy, seedB, 171}, {sandy, seedB, 173}, {sandy, seedA, 189}, {sandy, seedA, 182}, {sandy, seedB, 177}, {sandy, seedA, 176}}}
Schritt 3
Table[{x[[1, 1]], N[Mean[x[[All, -1]]]]}, {x, bySoilType}]
Ausgabe
{{clay, 180.}, {silty, 181.}, {sandy, 176.57142857142858}}
Schritt 4
bySeedType = GatherBy[agdata, #[[2]]&]
Ausgabe
{{{clay, seedB, 175}, {silty, seedB, 180}, {clay, seedB, 165}, {sandy, seedB, 171}, {sandy, seedB, 173}, {silty, seedB, 174}, {sandy, seedB, 177}, {clay, seedB, 175}, {silty, seedB, 181}, {silty, seedB, 190}}, {{sandy, seedA, 168}, {clay, seedA, 184}, {sandy, seedA, 189}, {clay, seedA, 186}, {clay, seedA, 192}, {clay, seedA, 184}, {clay, seedA, 179}, {sandy, seedA, 182}, {silty, seedA, 180}, {sandy, seedA, 176}}}
Schritt 5
Table[{x[[1, 2]], N[Mean[x[[All, -1]]]]}, {x, bySeedType}]
Ausgabe
{{seedB, 176.1}, {seedA, 182.}}
Schritt 6
Table[{x[[1, 2]], {N[Min[x[[All, -1]]]], N[Max[x[[All, -1]]]]}}, {x, bySeedType}]
Ausgabe
{{seedB, {165., 190.}}, {seedA, {168., 192.}}}
Schritt 7
meddata = {{drugB, 67, 18}, {drugB, 48, 18}, {drugA, 33, 16}, {drugB, 76, 33}, {drugB, 33, 3}, {placebo, 40, 15}, {drugB, 78, 28}, {drugB, 54, 13}, {placebo, 46, 23}, {drugA, 36, 12}, {drugA, 69, 30}, {drugA, 78, 40}, {placebo, 77, 37}, {drugA, 79, 36}, {drugA, 45, 16}, {drugA, 36, 18}, {drugA, 58, 24}, {placebo, 25, 9}, {drugB, 75, 25}, {drugB, 22, 3}, {placebo, 51, 25}, {placebo, 27, 8}, {placebo, 47, 20}, {placebo, 69, 34}, {drugB, 52, 16}};

Keine Ausgabe - dieser Schritt bereitet etwas für den nächsten vor.

Schritt 8
byDrug = GatherBy[meddata, First]
Ausgabe
{{{drugB, 67, 18}, {drugB, 48, 18}, {drugB, 76, 33}, {drugB, 33, 3}, {drugB, 78, 28}, {drugB, 54, 13}, {drugB, 75, 25}, {drugB, 22, 3}, {drugB, 52, 16}}, {{drugA, 33, 16}, {drugA, 36, 12}, {drugA, 69, 30}, {drugA, 78, 40}, {drugA, 79, 36}, {drugA, 45, 16}, {drugA, 36, 18}, {drugA, 58, 24}}, {{placebo, 40, 15}, {placebo, 46, 23}, {placebo, 77, 37}, {placebo, 25, 9}, {placebo, 51, 25}, {placebo, 27, 8}, {placebo, 47, 20}, {placebo, 69, 34}}}
Schritt 9
describe[values_] := {Length[values], Mean[values], Median[values], {Min[values], Max[values]}}

Keine Ausgabe - dieser Schritt bereitet etwas für den nächsten vor.

Schritt 10
Table[{x[[1, 1]], describe[N[x[[All, -1]]]]}, {x, byDrug} ]
Ausgabe
{{drugB, {9, 17.444444444444443, 18., {3., 33.}}}, {drugA, {8, 24., 21., {12., 40.}}}, {placebo, {8, 21.375, 21.5, {8., 37.}}}}
Schritt 11
byAgeGroup = GatherBy[meddata, IntegerPart[#[[2]] / 10]&]
Ausgabe
{{{drugB, 67, 18}, {drugA, 69, 30}, {placebo, 69, 34}}, {{drugB, 48, 18}, {placebo, 40, 15}, {placebo, 46, 23}, {drugA, 45, 16}, {placebo, 47, 20}}, {{drugA, 33, 16}, {drugB, 33, 3}, {drugA, 36, 12}, {drugA, 36, 18}}, {{drugB, 76, 33}, {drugB, 78, 28}, {drugA, 78, 40}, {placebo, 77, 37}, {drugA, 79, 36}, {drugB, 75, 25}}, {{drugB, 54, 13}, {drugA, 58, 24}, {placebo, 51, 25}, {drugB, 52, 16}}, {{placebo, 25, 9}, {drugB, 22, 3}, {placebo, 27, 8}}}
Schritt 12
Table[{10IntegerPart[x[[1, 2]] / 10], describe[N[x[[All, -1]]]]}, {x, byAgeGroup}]//Sort
Ausgabe
{{20, {3, 6.666666666666667, 8., {3., 9.}}}, {30, {4, 12.25, 14., {3., 18.}}}, {40, {5, 18.4, 18., {15., 23.}}}, {50, {4, 19.5, 20., {13., 25.}}}, {60, {3, 27.333333333333332, 30., {18., 34.}}}, {70, {6, 33.166666666666664, 34.5, {25., 40.}}}}
Schritt 13
byDrugAndAgeGroup = GatherBy[meddata, {First[#], IntegerPart[#[[2]] / 10]}&]
Ausgabe
{{{drugB, 67, 18}}, {{drugB, 48, 18}}, {{drugA, 33, 16}, {drugA, 36, 12}, {drugA, 36, 18}}, {{drugB, 76, 33}, {drugB, 78, 28}, {drugB, 75, 25}}, {{drugB, 33, 3}}, {{placebo, 40, 15}, {placebo, 46, 23}, {placebo, 47, 20}}, {{drugB, 54, 13}, {drugB, 52, 16}}, {{drugA, 69, 30}}, {{drugA, 78, 40}, {drugA, 79, 36}}, {{placebo, 77, 37}}, {{drugA, 45, 16}}, {{drugA, 58, 24}}, {{placebo, 25, 9}, {placebo, 27, 8}}, {{drugB, 22, 3}}, {{placebo, 51, 25}}, {{placebo, 69, 34}}}
Schritt 14
Table[{x[[1, 1]], 10IntegerPart[x[[1, 2]] / 10], describe[N[x[[All, -1]]]]}, {x, byDrugAndAgeGroup}]//Sort//Grid
Ausgabe
Grid[{{drugA, 30, {3, 15.333333333333334, 16., {12., 18.}}}, {drugA, 40, {1, 16., 16., {16., 16.}}}, {drugA, 50, {1, 24., 24., {24., 24.}}}, {drugA, 60, {1, 30., 30., {30., 30.}}}, {drugA, 70, {2, 38., 38., {36., 40.}}}, {drugB, 20, {1, 3., 3., {3., 3.}}}, {drugB, 30, {1, 3., 3., {3., 3.}}}, {drugB, 40, {1, 18., 18., {18., 18.}}}, {drugB, 50, {2, 14.5, 14.5, {13., 16.}}}, {drugB, 60, {1, 18., 18., {18., 18.}}}, {drugB, 70, {3, 28.666666666666668, 28., {25., 33.}}}, {placebo, 20, {2, 8.5, 8.5, {8., 9.}}}, {placebo, 40, {3, 19.333333333333332, 20., {15., 23.}}}, {placebo, 50, {1, 25., 25., {25., 25.}}}, {placebo, 60, {1, 34., 34., {34., 34.}}}, {placebo, 70, {1, 37., 37., {37., 37.}}}}]

Verwendete Funktionen

Verwandte Rezepte

Alle Rezepte · Funktionsreferenz · Dies aus einem MCP-Client verwenden