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]]
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.Galili@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 <sushikyc@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]]
On Apr 26, 2010, at 12:29 PM, Su Chu 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)> x[ c( which.max(x) -min(which(x[which.max(x):1] < 0)) +1, + which.max(x) +min(which(x[which.max(x):length(x)] < 0)) -1) ] [1] -2 -5> > 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 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.David Winsemius, MD West Hartford, CT
Possibly Parallel Threads
- Finding an order for an hclust (dendrogram) object without intersections
- Two questions, first about contingency tables, and second about table () and data.frame (), from a visually impaired user.
- Where can I find a working libeay32.dll file for RCurl ?
- Performing basic Multiple Sequence Alignment in R?
- Importing tRNA data into R ?