The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Help: Sum or average of Y on sub X range

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
redman Posted - 07/13/2016 : 07:07:38 AM
Origin Ver. and Service Release (Select Help-->About Origin): Originpro 2016 sr2
Operating System: Win10 x64

I just wonder if there is a way to get the sum or average of Y according to a sub range of X (bin number of X)? For example, I have two types of data, [time (X, in min) - Temperature (Y)] and [azimuthal angle (X, in degree) - number of objects (Y)], how can I get the average temperature ever 5 (or 10, 15 etc.) min, or the total number of objects ever 5 or 10 deg of the azimuthal angle? Another complicated example is that If we have a student list of a school with name, grade, age, gender, etc. How can we obtain the total students in different grades, sub-age ranges etc.?
The aim is to achieve statistics of a column (or row) according to the bin size/number of another column (or row)
Thanks in advance!
4   L A T E S T    R E P L I E S    (Newest First)
AmandaLu Posted - 08/03/2016 : 05:14:58 AM
Hi,

Please try X-Function reducexy. set subgroup = inc so you can calculate mean or sum of Y values in different X subranges. Here is the detailed document of reducexy:

http://www.originlab.com/doc/X-Function/ref/reducexy

Thanks,
Amanda
OriginLab Technical Service
redman Posted - 07/15/2016 : 09:20:26 AM
Thanks a lot for Yuki and Hedio's replies. Yuki's method is good enough for me. Wish this feature can be included in the future version.
yuki_wu Posted - 07/15/2016 : 06:00:49 AM
Hi redman,

As Hideo said, there is currently no straightforward way for that, but I think you can use the functions of sumif, averageif and countif with loop by labtalk.

Here is an example.

It is supposed that you have a data of azimuthal angle in col(A) from 1 to 20 and a data of number of objects in col(B), you can get the total number of objects ever 5 deg of the azimuthal angle in col(C) by the scripts below:


//define a range to store the results
range nn=[Book1]1!3;
for(ii=1; ii<=4; ii++)  
{
//define the sum variable
double aa;
//calculate the end and start of each bin
double bb=(ii-1)*5; 
//calculate the sum value of each bin
aa=sumif(col(B),"col(A) > bb && col(A) <= (bb+5)"); 
nn[ii]=aa;
}




If you want get the average or count of each bin, you can replace sumif with averageif or countif. More details can be found in these pages:
http://www.originlab.com/doc/LabTalk/ref/Sumif-func
http://www.originlab.com/doc/LabTalk/ref/Averageif-func
http://www.originlab.com/doc/LabTalk/ref/Countif-func
Hideo Fujii Posted - 07/14/2016 : 1:41:14 PM
Hi redman,

> If we have a student list of a school with name, grade, age, gender, etc. How can we obtain
> the total students in different grades, sub-age ranges etc.?

So, you want to make the group descriptive statistics by a script instead of from menu
("Stats> Descriptive Stats> Stats on Columns"), right?

Unfortunately, the x-command colstats for the column descriptive statistics seems lacking
the options for group variables. If so, there is currently no straightforward way for that.

Then, how about the work-around by utilizing an Analysis Template like following?:
1) Determine how many nesting levels of group variables you want to have, and make a sample 
  worksheet with appropriate number of columns. 
2) Run the descriptive statistics of columns with the group variables setting the 
  recalculation mode to "Auto".
3) Save the workbook as an analysis template, say with name "myGroupStatsBook.ogw". 
  ("File> Save Workbook as Analysis Template" menu)
4) From your script, open the analysis template by:
    doc -o "C:\mydata\myGroupStatsBook.ogw";
  If desired you can put the names of group variables into their column's long names.
5) Copy the data into the opened workbook, and you get the aggregated statistics automatically.

There might be straightforward, and nicer solutions.

Hope this work-around helps.

--Hideo Fujii
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000