Try this:


func <- function(x)
{
which.negative <- which(x<0)
index.to.return <- which.negative[which.negative > which.max(x)][1]
return(index.to.return)
}

func(x)


Best,
Tal

----------------Contact
Details:-------------------------------------------------------
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Mon, Apr 26, 2010 at 7:29 PM, Su Chu <sushi...@gmail.com> wrote:

> Hi there,
>
> I am working on a project that requires me to find the point at which
> values
> become negative in a sequence about the max.
>
> For example, say I have some sequence:
>
> x=c(-12, -2,-19, 0, -14, -2, 9,10,20,35,56,89,60,39,12,8,-5,-2,0,10)
>
> In this sequence, the max is 89, and I need to identify that -2 and -5 are
> the points at which the values* first *become negative about the max and
> retrieve their index values.
>
> I was hoping for some help in finding a way to automate this procedure, as
> I
> have over 100 vectors of this kind where I must find the two values about
> the max.
>
> Could anyone help? I would really, really appreciate it!
>
>
> Thank you so much!
>
> Best,
> Su
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to