moving-average

In R, average row value until hit a specific condition, then restart, with output in new column

做~自己de王妃 提交于 2019-12-12 10:24:23
问题 I am working with GPS data and trying to figure out how to average the 11th-15th fixes for latitude and longitude. I have seen solutions in similar questions for how to average every n rows. The problem is that occasionally the satellites bomb out and the fixes stop at 13 or 14. So, in these cases, I only want to average 3 or 4 values instead of 5. So I am looking to average values for latitude and longitude starting from where the number in series is 11 until the number in series drops again

Efficient rolling trimmed mean with Python

此生再无相见时 提交于 2019-12-12 08:41:56
问题 What's the most efficient way to calculate a rolling (aka moving window) trimmed mean with Python? For example, for a data set of 50K rows and a window size of 50, for each row I need to take the last 50 rows, remove the top and bottom 3 values (5% of the window size, rounded up), and get the average of the remaining 44 values. Currently for each row I'm slicing to get the window, sorting the window and then slicing to trim it. It works, slowly, but there has to be a more efficient way.

How to calculate moving average by specified grouping and deal with NAs

六月ゝ 毕业季﹏ 提交于 2019-12-11 19:04:09
问题 I have a data.table which needs a moving average to be calculated on the previous n days of data (let's use n=2 for simplicity, not incl. current day) for a specified grouping (ID1, ID2). The moving average should attempt to include the last 2 days of values for each ID1-ID2 pair. I would like to calculate moving average to handle NAs two separate ways: 1. Only calculate when there are 2 non-NA observations, otherwise avg should be NA (e.g. first 2 days within an ID1-ID2 will always have NAs)

How to single out values in a database based on date being month-end?

China☆狼群 提交于 2019-12-11 18:20:03
问题 I have a problem where I need to query a database which includes multiple lines of trade activity for the past 90 days. Currently the query is built to determine the average amount over the 90 day period - so each day has a single exposure value and the query helps us determine the average exposure over 90 days by just summing the daily values and then dividing by 90. And it does this as the date rolls forward, so the value is updated each day the query is run. The above is simple enough to

Grouping data in R to perform a function

心不动则不痛 提交于 2019-12-11 11:59:07
问题 Here is an example of my data: id score 1 82 0.50000 2 82 0.39286 3 82 0.56250 4 328 0.50000 5 328 0.67647 6 328 0.93750 7 328 0.91667 I want to make a column of moving average's of scores for each id. So I need to somehow group the data by id then apply a MA function to that grouped data and then have the output as another column "MA_score" I would like my output to look like this: id score MA_score 1 82 0.50000 NULL 2 82 0.39286 0.xxxx 3 82 0.56250 NULL 4 328 0.50000 NULL 5 328 0.67647 0

How to calculate the rolling average of a C# array list?

自古美人都是妖i 提交于 2019-12-11 10:47:15
问题 I'm trying to calculate the rolling averages of every four values in an array list and add those values to a separate array list. My original array list is called numlist and it contains values from 1 to 9 List<int> numlist = new List<int>(); numlist.Add(1); numlist.Add(2); numlist.Add(3); numlist.Add(4); numlist.Add(5); numlist.Add(6); numlist.Add(7); numlist.Add(8); numlist.Add(9); When it calculates rolling averages, it should do it in an way like this: first average = (1+2+3+4)/4 second

How TradingView Pine Script RMA function works internally?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 09:50:02
问题 I'm trying to re-implement the rma function from TradingView pinescript but I cannot make it output the same result as the original function. Here is the code I developed, the code is basically the ema function, but it differs greatly from the rma function plot result when charting: //@version=3 study(title = "test", overlay=true) rolling_moving_average(data, length) => alpha = 2 / (length + 1) sum = 0.0 for index = length to 0 if sum == 0.0 sum := data[index] else sum := alpha * data[index]

fread and fwrite parameters in C

≡放荡痞女 提交于 2019-12-11 05:07:21
问题 I am trying to adapt a matlab program to C, my problem is in the fwrite and fread function. On matlab I have: fid = fopen ('sweep_100_3400.pcm','rb'); s = fread (fid, 'int16'); My doubt is, in C there are two more parameters in fread and fwrite function. fread(void*, size_t, size_t, FILE*); fwrite(const void*, size_t, size_t, FILE*); In my C code I have: arq = fopen("C:\\Users\\iago_\\Desktop\\MediaMovel\\sweep_100_3400.pcm", "rb"); fread(x, sizeof(double), itera, arq); fclose(arq); x is the

how to use forecast function for simple moving average model in r?

六眼飞鱼酱① 提交于 2019-12-11 03:09:39
问题 I want to predict the future values for my simple moving average model. I used the following procedure: x <- c(14,10,11,7,10,9,11,19,7,10,21,9,8,16,21,14,6,7) df <- data.frame(x) dftimeseries <- ts(df) library(TTR) smadf <- SMA(dftimeseries, 4) # lag is 4 library(forecast) forecasteddf <- forecast(smadf, 4) # future 4 values When run the above code, my forecast values are the same for all the next 4 days. Am I coding it correctly? Or, am I conceptually wrong? The same is the case with

Moving average query MS Access

偶尔善良 提交于 2019-12-11 00:55:27
问题 I am trying to calculate the moving average of my data. I have googled and found many examples on this site and others but am still stumped. I need to calculate the average of the previous 5 flow for the record selected for the specific product. My Table looks like the following: TMDT Prod Flow 8/21/2017 12:01:00 AM A 100 8/20/2017 11:30:45 PM A 150 8/20/2017 10:00:15 PM A 200 8/19/2017 5:00:00 AM B 600 8/17/2017 12:00:00 AM A 300 8/16/2017 11:00:00 AM A 200 8/15/2017 10:00:31 AM A 50 I have