The R Project SVN R

Rev

Rev 44220 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44220 Rev 51908
Line 49... Line 49...
49
    have_names = nm != R_NilValue;
49
    have_names = nm != R_NilValue;
50
    PROTECT(counts = allocVector(INTSXP, nlevs));
50
    PROTECT(counts = allocVector(INTSXP, nlevs));
51
    for (i = 0; i < nlevs; i++) INTEGER(counts)[i] = 0;
51
    for (i = 0; i < nlevs; i++) INTEGER(counts)[i] = 0;
52
    for (i = 0; i < nobs; i++) {
52
    for (i = 0; i < nobs; i++) {
53
	j = INTEGER(f)[i % nfac];
53
	j = INTEGER(f)[i % nfac];
-
 
54
	if (j != NA_INTEGER) {
-
 
55
	    /* protect against malformed factors */
-
 
56
	    if (j > nlevs || j < 1) error(_("factor has bad level"));
54
	if (j != NA_INTEGER) INTEGER(counts)[j - 1]++;
57
	    INTEGER(counts)[j - 1]++;
-
 
58
	}
55
    }
59
    }
56
    /* Allocate a generic vector to hold the results. */
60
    /* Allocate a generic vector to hold the results. */
57
    /* The i-th element will hold the split-out data */
61
    /* The i-th element will hold the split-out data */
58
    /* for the ith group. */
62
    /* for the ith group. */
59
    PROTECT(vec = allocVector(VECSXP, nlevs));
63
    PROTECT(vec = allocVector(VECSXP, nlevs));