-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrowmins.c
More file actions
38 lines (28 loc) · 707 Bytes
/
rowmins.c
File metadata and controls
38 lines (28 loc) · 707 Bytes
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
#include <R.h>
#include <Rdefines.h>
#include <stdio.h>
SEXP rowMins(SEXP x, SEXP colRange, SEXP dims) {
SEXP n;
int i,j;
dims = coerceVector(dims, INTSXP);
int I = INTEGER (dims)[0];
int J = INTEGER (dims)[1];
x = coerceVector(x, REALSXP);
double* X = REAL(x);
colRange = coerceVector(colRange, INTSXP);
int K = length(colRange);
int* col = INTEGER(colRange);
PROTECT(n = allocVector(REALSXP, I));
double* ans = REAL(n);
for(i = 0; i < I; ++i){
ans[i] = X[i + I*(col[0] - 1)];
}
for(i = 0; i < I; ++i){
for(j=0;j < K; ++j){
if( ans[i] > X[ i + I*(col[j]-1) ] )
ans[i] = X[ i + I*(col[j]-1) ];
}
}
UNPROTECT(1);
return(n);
}