On 15.08.2014 07:15, PO SU wrote:
> Dear Rcppusers,
> When i am learning Rcpp , i meet the following function, i can't
> figure out its use, May you explain to me ?

It's similar to std::find_if(): it returns the index of the first element in a list that matches a given predicate.

For example, consider a function "odd", which returns TRUE for odd numbers, FALSE otherwise. f4(odd, c(4,6,10,15,3,8)) would return 4, because the fourth number in the list (15) is the first odd number.


Remember that R will always work on vectors - if the predicate returns TRUE, that's actually a vector with a single value TRUE. Hence the LogicalVector and the check for res[0] instead of res.




--
Christian Authmann
Philipps-Universität Marburg
Fachbereich Mathematik und Informatik
AG Datenbanksysteme
Hans-Meerwein-Straße
D-35032 Marburg
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to