cancel
Showing results for
Show  only  | Search instead for
Did you mean:
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
Level II

## rolling moving average

Hi,

I want to create a new column "moving average" and want this column to do rolling average of temp based on ID. I attached a sample file here. Can you please help with the formula?

thanks!

7 REPLIES 7
Super User

## Re: rolling moving average

Assuming that your definition of "Rolling Average" is a "Moving Average" the formula is

`Col Moving Average( :Temp, :ID )`

Documentation and Examples of the Col Moving Average() are in the Scripting Index

Help==>Scripting Index

Jim
Level II

## Re: rolling moving average

Hi Jim

I used this formula but this does not deliver what I was expecting.

First: I want to create column which is the mean of temp by ID

Then, I want to mean of the new column over "X (X is user defined)" number of IDs.

Can you please help with that?

Super User

## Re: rolling moving average

If you read the documentation on the Col Moving Average() function, it allows for the setting of what I believe you are referring to as X.

Could you please provide some sample results.  I am still not understanding your request.

Jim
Level II

## Re: rolling moving average

I looked into big class sample data set and created a column:

``Col Moving Average( :height, 1, 5, 0, :sex )``

What does 5 do in the calculation?

I was able to manually calculate the moving average until the row#9---How was 58.833333333 calculated? I am not able to generate the same number manually

Super User

## Re: rolling moving average

The 5 in the function call is specifying the number of rows before the current row to include in the moving average.  You can actually specify the function in the following way.....which is really the way it should be called, to make the script more readable

``Col Moving Average( :height, weighting=1, Before=5, after=0, :sex )``

In your manual calculation you have to remember that the moving average is being tracked for both Males and Females.  And the average does not restart every time the data changes from F to M or M to F.  It is treating the calculations as if there are 2 separate columns.

Jim
Level IV

## Re: rolling moving average

I guess sometimes the data needs to be sorted (e.g. time-dependent column).
Or is there an argument in the function that is referring to such cases?

Thanks, Adam
Super User

## Re: rolling moving average

Col Moving Average() will be calculated separately for each level of the By() columns, such as the Sex column in my example, however, the moving average will be calculated in row order.  So the data may have to be sorted to get the desired results.

Jim