<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><br><br><div>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.</div><div><br></div><br><br><div>--<br><div>PO SU</div><div><a href="mailto:rcppmail@163.com" _src="mailto:rcppmail@163.com">rcppmail@163.com</a> </div><div>Majored in Statistic Shanghai JiaoTong University</div><div><br></div></div><div id="divNeteaseMailCard"></div><br><pre><br>At 2014-08-15 03:31:44, "Christian Authmann" <authmanc@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
</pre></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>