Re: Aggregating data and graphing it
- To: mathgroup at smc.vnet.net
- Subject: [mg101950] Re: [mg101920] Aggregating data and graphing it
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Fri, 24 Jul 2009 06:11:42 -0400 (EDT)
- Reply-to: hanlonr at cox.net
valueCounts[data_?MatrixQ, position_Integer] := {#[[1, position]], #[[2]]} & /@ Tally[data, #1[[position]] == #2[[position]] &] data = {{10, 1, 120}, {20, 5, 100}, {30, 7, 20}, {10, 1, 130}, {20, 7, 134}, {10, 1, 23}, {20, 7, 68}, {30, 7, 230}, {40, 5, 235}, {10, 1, 125}}; valueCounts[data, 1] {{10, 4}, {20, 3}, {30, 2}, {40, 1}} valueCounts[data, 2] {{1, 4}, {5, 2}, {7, 4}} Histogram3D[Most /@ data] Histogram3D[Most /@ data, {4, 3}] Histogram[First /@ data] Histogram[First /@ data, 4] Histogram[#[[2]] & /@ data] Histogram[#[[2]] & /@ data, 3] Bob Hanlon ---- Parita <parita.patel at gmail.com> wrote: ============= Hi I am looking for a function that works similar to group by in SQL. I have a data set with 3 columns (Metric1, Metric2, Height). This data set can have multiple values of height by metric1 and metric2. I would like to do the following 1) Sum height by metric1 and metric2. Generate a 3D histogram plot with metric1 and metric2 on x and y axis and the summed up height on z axis 2) Sum height by metric1. Generate a histogram plot with metric1 on x axis and summed up height on y axis I am able to generate histograms or 3D histograms which counts the instances of duplicates. However, I am not sure how to generate histograms after summing the data Following code counts the instances of duplicates by metric1 and metric2 and generates a 3D histogram plot with metric1 and metric2 on x and y axis and the count of height on z axis data ={{10,1}, {20,5}, {30,7}, {10,1}, {20,7}, {10,1}, {20,7}, {30,7}, {40,5}, {10,1}}; Histogram3D[data] Following is the data set that can be used to implement tasks 1 and 2 above data ={{10,1,120}, {20,5,100}, {30,7,20}, {10,1,130}, {20,7,134}, {10,1,23}, {20,7,68}, {30,7,230}, {40,5,235}, {10,1,125}}; Thanks for your help