Thank you a ton! This is perfect!

From: Jean V Adams [via R] [mailto:ml-node+s789695n4636370...@n4.nabble.com]
Sent: Thursday, July 12, 2012 4:59 PM
To: Lauren Vogric
Subject: Re: Grabbing Indexes of a certain standard deviation

I wrote a little function called first() to help with situations like
this.  It returns a 1 every time an element of a vector is different from
the previous element, and a 0 otherwise.

first <- function(x) {
    L <- length(x)
    c(1, 1-(x[-1]==x[-L]))
    }

sd <- 1
residuals <- c(1, 2.1, 3, 4, 3, 1, 0, -4, -1)
# logical, indicating if the residual exceeds 2 standard deviations
exceed <- abs(residuals) > (2*sd)
# indices of the first exceeding residual of a series
which(first(exceed) & exceed)

Jean


gcm <[hidden email]</user/SendEmail.jtp?type=node&node=4636370&i=0>> wrote on 
07/12/2012 11:07:49 AM:

> I have a graph of residuals and I am attempting to get a list of the
indexes
> of each time the residual is greater than 2 standard deviations or less
than
> -2 standard deviations, but only the first point of the section. And
then
> I'd also need the first point where the point returns to the range
between
> +/- 2 standard deviations.
> So basically if my standard deviation=1 and my residuals=c(1, 2.1, 3, 4,
3,
> 1, 0, -4, -1) I want it to grab the second number, where it exceeds 2
> standard deviations and the 6th where it returns to less than 2 standard
> deviations. Also, it would grab -4 (or residuals[ 8]) and -1
(residuals[9])

        [[alternative HTML version deleted]]

______________________________________________
[hidden email]</user/SendEmail.jtp?type=node&node=4636370&i=1> 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.

________________________________
If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Grabbing-Indexes-of-a-certain-standard-deviation-tp4636318p4636370.html
To unsubscribe from Grabbing Indexes of a certain standard deviation, click 
here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4636318&code=bHZvZ3JpY0BncmFoYW1jYXBpdGFsLmNvbXw0NjM2MzE4fDUwNDUzMzMwMQ==>.
NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>


--
View this message in context: 
http://r.789695.n4.nabble.com/Grabbing-Indexes-of-a-certain-standard-deviation-tp4636318p4636429.html
Sent from the R help mailing list archive at Nabble.com.
        [[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