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 [email protected] Majored in Statistic Shanghai JiaoTong University At 2014-08-15 03:31:44, "Christian Authmann" <[email protected]> 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
_______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
