It may be easier to use the match function which is defined to return the index of the first match.
> corretor <- c(15, 23, 27, 34, 25, 27, 26) > match(27, corretor) [1] 3 Marc Schwartz <[EMAIL PROTECTED]> writes: > On Fri, 2003-09-19 at 13:15, Cezar Augusto de Freitas Anselmo wrote: > > Hi, all. I'd like to know if exists a manner to get the first index where > > a condition is attained in a vector. For example, > > > > There is a better solution than > > > > first.index <- table(subject[corretor==27])[1] > > > > (give me the subject for the first time that corretor is 27)? > > > > Thanks, > > > first.index <- min(which(corretor == 27)) > > For example: > > corretor <- c(15, 23, 27, 34, 25, 27, 26) > > which(corretor == 27) > [1] 3 6 > > min(which(corretor == 27)) > [1] 3 > > See ?which ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
