Hello
I want to create a moving average of the last three values in Col1 and put it in Col2
In Excel it looks like the screenshot below.
I cant't figure out how to do it in LC
There will be a few thousand lines of data so I don't know if I should work with arrays or fields
Any hints?
Moving average
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Moving average
Hi.
So much fun.
On a new card, make a table field, and put any small numbers into item 1 of the first 20 lines. Maybe in a button somewhere:
Now in another button script:
Could you do this other ways? Yes.
Craig
So much fun.
On a new card, make a table field, and put any small numbers into item 1 of the first 20 lines. Maybe in a button somewhere:
Code: Select all
on mouseUp
set the itemDel to tab
repeat with y = 1 to 20
put random(20) into item 1 of line y of fld 1
end repeat
end mouseUp
Code: Select all
on mouseUp
get fld 1
set the itemDel to tab
set the numberFormat to "#.00"
repeat with y = 3 to 20
put (item 1 of line (y-2) of it + item 1 of line (y-1) of it + item 1 of line y of it) / 3 into item 2 of line y of fld 1
end repeat
end mouseUp
Craig
Re: Moving average
Thanks Craig, that put me on the right track
Re: Moving average
The thing about this, really, is to be comfortable using "chunks", items, lines, words, chars, etc.
In a way this method is clunky, using the "format" of the dataSet to massage the dataSet. And if you are doing this sort of thing with a lot of data, I would keep everything in a variable, and load the table field all at once in the last line. I should have done that anyway, just to do it right the first time.
Craig
In a way this method is clunky, using the "format" of the dataSet to massage the dataSet. And if you are doing this sort of thing with a lot of data, I would keep everything in a variable, and load the table field all at once in the last line. I should have done that anyway, just to do it right the first time.
Code: Select all
...
repeat with y = 3 to 20
put (item 1 of line (y-2) of it + item 1 of line (y-1) of it + item 1 of line y of it) / 3 into item 2 of line y of it
end repeat
put it into fld 1...