https://github.com/cran/cutpointr
Raw File
Tip revision: 2900dc24d2c5a7d8fdb3f1abb1540fb704e51742 authored by Christian Thiele on 15 February 2021, 13:40:03 UTC
version 1.1.0
Tip revision: 2900dc2
which.cpp
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
IntegerVector which_are_num(NumericVector x, double a) {
    int nx = x.size();
    std::vector<int> y;
    y.reserve(nx);

    for(int i = 0; i < nx; i++) {
        if (x[i] == a) y.push_back(i+1);
    }

    return wrap(y);
}

// [[Rcpp::export]]
IntegerVector which_are_char(CharacterVector x, String a) {
    int nx = x.size();
    std::vector<int> y;
    y.reserve(nx);

    for(int i = 0; i < nx; i++) {
        if (x[i] == a) y.push_back(i+1);
    }

    return wrap(y);
}
back to top