I have been trying to implement apply function in Rcpp so far the code looks like this
//[[Rcpp::export]]
NumericVector apply(NumericMatrix x,int dim,Functio
The answers are, in order, "yes" and "yes", and you may want to read the "Rcpp Introduction" which contains the following lapply()
example:
R> src <- '
+ Rcpp::List input(data);
+ Rcpp::Function f(fun);
+ Rcpp::List output(input.size());
+ std::transform(input.begin(), input.end(), output.begin(), f);
+ output.names() = input.names();
+ return output;
+ '
R> cpp_lapply <- cxxfunction(signature(data = "list", fun = "function"),
+ src, plugin = "Rcpp")
This was written for inline rather than Rcpp Attributes because that is how we rolled back in the day. We have more apply-alike functions in other examples and unit tests...
You have not specified what arguments your function f()
takes and returns which makes fixing your question a little trickier.