Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Moving Average

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Jan 3, 2019 4:56 AM
| Last Modified: Jan 3, 2019 4:59 AM
(6993 views)

I have a table called drugs with columns drug and result, how do I calculate the moving average of the result column by taking the first 4 rows followed by the next 4 rows and similarly continue. Pfa the sample table for reference.

- Tags:
- Mean
- moving average

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

The formula to use is

```
If( Mod( Row(), 4 ) == 0,
Mean( :Result[Index( Row() - 3, Row() )] )
)
```

I have attached your example data table, with a new column with the formula in it

Jim

10 REPLIES 10

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

hello ,

you can try with Formula column --> row --> moving average

Gianpaolo Polsinelli

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

Could you please explain the next step after this, I want to calculate the average of 4 consecutive samples

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

Do you have 4 columns of results, or 4 times as many rows as you show in your sample data table?

Jim

Highlighted
##

I want to generate the moving average column as shown in the attached table, for every 4 rows I need to calculate the average

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

The formula to use is

```
If( Mod( Row(), 4 ) == 0,
Mean( :Result[Index( Row() - 3, Row() )] )
)
```

I have attached your example data table, with a new column with the formula in it

Jim

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

Thanks this worked

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

I think this will give you the moving average that you want (4 rows before and 4 rows after).

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

this did not work

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Moving Average

Create a new column in your data table, and apply the folloing formula

`Col Moving Average( :Result, weighting = 1, before = 3, :Drug )`

Jim

Article Labels

There are no labels assigned to this post.