[R] Position in a vector of the last value > n

Henrique Dallazuanna wwwhsd at gmail.com
Thu Jul 10 15:41:58 CEST 2008


Try this:

v[max(which(v > 20))]

On Thu, Jul 10, 2008 at 9:41 AM, Thaden, John J <ThadenJohnJ at uams.edu> wrote:
> This shouldn't be hard, but it's just not
> coming to me:
> Given a vector, e.g.,
> v <- c(20, 134, 45, 20, 24, 500, 20, 20, 20)
> how can I get the index of the last value in
> the vector having a value greater than n, in
> this case, greater than 20?  I'm looking for
> an efficient function I can use on very large
> matrices, as the FUN argument in the apply()
> command.
>
> Confidentiality Notice: This e-mail message, including a...{{dropped:8}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list