Is there a Rcpp sugar for %in%?
For eg, I have the following statement in R
y <- c('XA','XB','XC','XF','XK','XL','XM','XN','XO','XP','XS','XU','XW','XY', 'DF','DS','AS','XL','FG')
x <- ifelse(y %in% c("XA","XB","XC","XF","XK","XL","XM","XN","XO","XP","XS","XU","XW","XY"),"KCA","KUS")
I am trying to use || in Rcpp for the above, where both x and y have been defined to be the type
std::vector<std::string>
The code snippet is
int n = y.size();
for (int i = 0; i < n; i++){
if (y[i] == 'XA' ||
y[i] == 'XB' ||
y[i] == 'XC' ||
y[i] == 'XF' ||
y[i] == 'XK' ||
y[i] == 'XL' ||
y[i] == 'XM' ||
y[i] == 'XN'||
y[i] == 'XO'||
y[i] == 'XP' ||
y[i] == 'XS' ||
y[i] == 'XU' ||
y[i] == 'XW' ||
y[i] == 'XY' ) {x[i] = 'KCA';}
else
{x[i] ='KUS';}
} //end of loop
But I get the following error:
ambiguous overload for operator'=='(operand types are 'std::basic_string<char>' and 'int')
Is there a sugar for
%in%
that I can use in Rcpp, or how do I use || in Rcpp here to avoid the error?