I am trying to run the following code. Honestly, I only know C ++, but I want to get the following function. Can you help me run this stupid example?
cppFunction(
'NumericVector abc(int x, int x_end, NumericVector y)
{
NumericVector z;
int x1 = x + x_end;
z = y[x:x1];
return(z);
}'
)
abc(3,c(0,1,10,100,1000,10000))
I see it...
error: expected ']' before ':' token
Update
Sorry, I forgot to mention that I need to generate a sequence of numbers from xto x1. The function IntegerVector::createonly creates a variable with xand x1not x, though x1. The example I gave was trivial. Now I updated this example. I need to do in C ++ what seq()does in R
Solution based on answer below (@SleuthEye)
Rcpp::cppFunction(
'NumericVector abc(int x, int x_end, NumericVector y)
{
NumericVector z;
Range idx(x,x_end);
z = y[idx];
return(z);
}'
)
abc(3,5,c(0,1,10,100,1000,10000))
[1] 100 1000 10000