LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate table average grouped by another field

Solved!
Go to solution

Hi - 

 

I am hoping to understand a simple way to calculate grouped summary stats from a table.  I'd like to calculate mean, standard deviation, and a number of quantiles (1%,2%, 5%, etc.) from a table.  I'd like these results to be grouped by other fields in the table.  I am providing a very simple example, but would like to be able to perform this calculation in an efficient way so that it works well for more complicated data sets.  My data sets have many grouped by terms and are not sorted by the grouping parameters.

 

In the example below, I'm showing how to calculate average values grouped by name.  I know I could sort them by name and look for changes in this parameter, then use those indeces to create subarrays and calculate averages from there.  I would prefer to use a function designed for this purpose like those available in SQL (minus the quantiles), JMP, and matlab.

 

Maybe the answer is use the mathscript function, but I've had issues with those mathscript windows being buggy in the past.

 

Is there a clean labview function which can perform these calculations?

 

Thanks,

Jennifer

 

Name Value Avg
John 0.537456 0.577731
John 0.91844  
John 0.279187  
John 0.758893  
John 0.394678  
Mary 0.007313 0.486202
Mary 0.935343  
Mary 0.432797  
Mary 0.569353  
0 Kudos
Message 1 of 10
(3,871 Views)

You can do some interesting things using Variant Attributes.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(3,851 Views)

Crossrulz beat me to it but variant attributes seems like a good solution here, since you can define the attributes to be any datatype.  I'll have to remember this for my own use as well.

aputman
0 Kudos
Message 3 of 10
(3,840 Views)

I get an error?

 

 

 

0 Kudos
Message 4 of 10
(3,834 Views)

I think the first Get Attribute needs an array, not a single value.  Crossrulz has auto-indexing turned on for it but I think that was an oversight.

aputman
0 Kudos
Message 5 of 10
(3,829 Views)

I had the empty array hooked to it, but then that for loop doesn't run and the mean/std/name arrays end up empty.

0 Kudos
Message 6 of 10
(3,822 Views)

attached vi and example data set

Download All
0 Kudos
Message 7 of 10
(3,821 Views)
Solution
Accepted by topic author DaveRines

Sorry, I can't open your VI but this is what I have for the first loop which stores the values into the variant.  Like I said, Crossrulz is the same as this except he has auto-indexing turned on for the empty array.  It should be turned off so that the datatype stored into the variant is an array.  

Example_VI.png

aputman
0 Kudos
Message 8 of 10
(3,804 Views)

Thanks all!  That worked.

0 Kudos
Message 9 of 10
(3,799 Views)

@aputman wrote:

I think the first Get Attribute needs an array, not a single value.  Crossrulz has auto-indexing turned on for it but I think that was an oversight.


Weird.  I specifically remember turning that autoindexing tunnel off.  Oh well.  We got there eventually.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(3,787 Views)