Вы можете использовать функцию in()
, доступную в Rcpp, чтобы воссоздать инфиксный оператор %in%
.
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::LogicalVector match_with_in(Rcpp::NumericVector x,
Rcpp::NumericVector y) {
// Mimic %in% with Rcpp
Rcpp::LogicalVector matched_values = Rcpp::in(x, y);
return matched_values;
}
Тест:
x = 5
y = c(4, 8, 10)
match_with_in(x, y)
#> [1] FALSE
z = c(4, 5, 10)
match_with_in(x, z)
#> [1] TRUE