[Rcpp-devel] What the rcpp function does ?

PO SU rcppmail at 163.com
Fri Aug 15 11:08:47 CEST 2014




Tks for your help! As you pointed out, I think i was confused by  'return a LogicalVector but only judging its first element', i forgot TRUE is length 1 logical vector.





--

PO SU
rcppmail at 163.com
Majored in Statistic Shanghai JiaoTong University





At 2014-08-15 03:31:44, "Christian Authmann" <authmanc at Mathematik.Uni-Marburg.de> wrote:
>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140815/0d817cc2/attachment.html>


More information about the Rcpp-devel mailing list