1 /***************************************************************************
2 Public methods:
3 SEXP mean2(SEXP x, SEXP idxs, SEXP naRm, SEXP refine)
4
5 Copyright Henrik Bengtsson, 2014
6 **************************************************************************/
7 #include <Rdefines.h>
8 #include "000.types.h"
9 #include "mean2_lowlevel.h"
10
mean2(SEXP x,SEXP idxs,SEXP naRm,SEXP refine)11 SEXP mean2(SEXP x, SEXP idxs, SEXP naRm, SEXP refine) {
12 SEXP ans;
13 R_xlen_t nx;
14 int narm, refine2;
15 double avg = NA_REAL;
16
17 /* Argument 'x': */
18 assertArgVector(x, (R_TYPE_INT | R_TYPE_REAL | R_TYPE_LGL), "x");
19 nx = xlength(x);
20
21 /* Argument 'naRm': */
22 narm = asLogicalNoNA(naRm, "na.rm");
23
24 /* Argument 'refine': */
25 refine2 = asLogicalNoNA(refine, "refine");
26
27 /* Argument 'idxs': */
28 R_xlen_t nidxs;
29 R_xlen_t *cidxs = validateIndices(idxs, nx, 1, &nidxs);
30
31 /* Double matrices are more common to use. */
32 if (isReal(x)) {
33 avg = mean2_dbl(REAL(x), nx, cidxs, nidxs, narm, refine2);
34 } else if (isInteger(x) || isLogical(x)) {
35 avg = mean2_int(INTEGER(x), nx, cidxs, nidxs, narm, refine2);
36 }
37
38 /* Return results */
39 PROTECT(ans = allocVector(REALSXP, 1));
40 REAL(ans)[0] = avg;
41 UNPROTECT(1);
42
43 return(ans);
44 } // mean2()
45
46
47 /***************************************************************************
48 HISTORY:
49 2015-07-04 [DJ]
50 o Supported subsetted computation.
51 2014-11-02 [HB]
52 o Created.
53 **************************************************************************/
54