[Rcpp-devel] Rcpp "version" of R's match function
Søren Højsgaard
sorenh at math.aau.dk
Thu Nov 15 00:08:53 CET 2012
Thanks! What I need to do is this
> match(c("b","k"), letters)
[1] 2 11
Regards
Søren
-----Original Message-----
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org] On Behalf Of Romain Francois
Sent: 15. november 2012 00:01
To: rcpp-devel at lists.r-forge.r-project.org
Subject: Re: [Rcpp-devel] Rcpp "version" of R's match function
Le 14/11/12 23:48, Søren Højsgaard a écrit :
> Dear all,
>
> I need to call R's match function from a c++ program so I can do
> Rcpp::Function R_match("match");
> Rcpp::NumericVector out = R_match(x_, table_);
>
> However, I wonder if there is such a "match" function in C++ that I can call (to avoid the extra overhead)?
>
> Any ideas would be welcome
>
> Regards
> Søren
We don't have one in Rcpp. It would not be too hard I guess to use some algorithms from the STL, e.g. std::find.
http://www.cplusplus.com/reference/algorithm/find/
Not easy to say more withou seeing exactly what you are trying to do.
For example, do you need to store "out" or is it enough to work one value at a time ...
Also, R's match returns an integer vector, so you probably want:
Rcpp::IntegerVector out = R_match(x_, table_);
otherwise you also pay for making the coercion to numeric on top of the
price you pay for calling back into R.
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy
blog: http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
More information about the Rcpp-devel
mailing list