-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcumulative_fxns.R
More file actions
66 lines (48 loc) · 1.06 KB
/
cumulative_fxns.R
File metadata and controls
66 lines (48 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#looks like I was kind of wrong about what cummax et al do; see ?cummax for more; leaving this for now, though
library(Rcpp)
cppFunction('int cum_prod(NumericVector x) {
int n = x.size();
int size = 0;
for(int i = 0; i < n; ++i) {
size += x[i];
}
return size;
}')
cppFunction('int cum_min(NumericVector x) {
int n = x.size();
int min = x[0];
for(int i = 1; i < n; ++i) {
if(x[i] < min){
min = x[i];
}
}
return min;
}')
cppFunction('int cum_max(NumericVector x) {
int n = x.size();
int max = x[0];
for(int i = 1; i < n; ++i) {
if(x[i] > max){
max = x[i];
}
}
return max;
}')
cppFunction('NumericVector diff_calc(NumericVector x, int y = 1) {
int n = x.size();
NumericVector out(n-y);
for(int i = (0+y); i < n; ++i) {
out[i-y] = x[i] - x[i-y];
}
return out;
}')
cppFunction('NumericVector range(NumericVector x) {
NumericVector range(2);
double result=0;
result = F1(a); min = pmin(x);
int max;
max = pmax(x);
range[0] = min;
range[1] = max;
return range;
}')