The R Project SVN R

Rev

Rev 20182 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20182 Rev 20184
Line 25... Line 25...
25
#include <R_ext/Error.h>
25
#include <R_ext/Error.h>
26
#include <R_ext/Arith.h>
26
#include <R_ext/Arith.h>
27
#include <R_ext/Applic.h>
27
#include <R_ext/Applic.h>
28
 
28
 
29
/* bincode  cuts up the data using half open intervals defined as [a,b)
29
/* bincode  cuts up the data using half open intervals defined as [a,b)
30
   bincode2 cuts up the data using half open intervals defined as (a,b]
-
 
31
 
-
 
32
 MM: Shouldn't we afford to collapse these two into one,
30
   (if right = FALSE) or (a, b] (if right = TRUE)
33
     There would have to be 'n' extra "if" evaluations only ... ?
-
 
34
 
-
 
35
*/
31
*/
36
void bincode(double *x, int *pn, double *breaks, int *pnb, int *code,
32
void bincode(double *x, int *pn, double *breaks, int *pnb, int *code,
37
	     int *right, int *include_border, int *naok)
33
	     int *right, int *include_border, int *naok)
38
{
34
{
39
    int i, lo, hi;
35
    int i, lo, hi;
Line 64... Line 60...
64
	    error("NA's in .C(\"bincode\",... NAOK=FALSE)");
60
	    error("NA's in .C(\"bincode\",... NAOK=FALSE)");
65
    }
61
    }
66
}
62
}
67
 
63
 
68
/* bincount is called by  hist(.)  [only]
64
/* bincount is called by  hist(.)  [only]
69
 *
-
 
70
 * bincount *counts* like bincode2, i.e. half open intervals defined as (a,b]
-
 
71
 */
65
 */
72
 
66
 
73
void bincount(double *x, int *pn, double *breaks, int *pnb, int *count,
67
void bincount(double *x, int *pn, double *breaks, int *pnb, int *count,
74
	      int *right, int *include_border, int *naok)
68
	      int *right, int *include_border, int *naok)
75
{
69
{
Line 100... Line 94...
100
		count[lo] += 1;
94
		count[lo] += 1;
101
	    }
95
	    }
102
	} else if (! *naok)
96
	} else if (! *naok)
103
	    error("NA's in .C(\"bincount\",... NAOK=FALSE)");
97
	    error("NA's in .C(\"bincount\",... NAOK=FALSE)");
104
}
98
}
105
 
-
 
106
 
-
 
107
/*-- UNUSED, but still in  ./ROUTINES --- eliminate both at once ! */
-
 
108
void bincode2(double *x, int *pn, double *breaks, int *pnb, int *code,
-
 
109
	      int *include_border, int *naok)
-
 
110
{
-
 
111
    int i, lo, hi;
-
 
112
    int n, nb1, new;
-
 
113
 
-
 
114
    n = *pn;
-
 
115
    nb1 = *pnb - 1;
-
 
116
 
-
 
117
    for(i=0 ; i<n ; i++)
-
 
118
	if(R_FINITE(x[i])) {
-
 
119
	    lo = 0;
-
 
120
	    hi = nb1;
-
 
121
	    if(x[i] <  breaks[lo] || breaks[hi] < x[i] ||
-
 
122
	       (x[i] == breaks[lo] && ! *include_border))
-
 
123
		/*             == */
-
 
124
		code[i] = NA_INTEGER;
-
 
125
	    else {
-
 
126
		while(hi-lo >= 2) {
-
 
127
		    new = (hi+lo)/2;
-
 
128
		    if(x[i] >  breaks[new])
-
 
129
			/*  == */
-
 
130
			lo = new;
-
 
131
		    else
-
 
132
			hi = new;
-
 
133
		}
-
 
134
		code[i] = lo+1;
-
 
135
	    }
-
 
136
	} else if (! *naok)
-
 
137
	    error("NA's in .C(\"bincode2\",... naok=FALSE)");
-
 
138
}
-