I'm having problems with a simple code in Rcpp. My problem is that I want to change a vector by passing it to a function. A example is:
//[[Rcpp::export]]
void ones(IntegerVector x, int lx){
int i;
for(i = 0; i < lx; i++){
x(i) = 1;
}
}
When I do in R:
x = rep(-1, 10)
ones(x, length(x))
the vector x do not change. How can i work this out?
edit: If I pass x as &x how do I change it's values?
edit: after trying the two methods proposed in the first two answers nothing changed.
edit: restarted Rstudio and now it works....... Is it a common problem for Rstudio users?