Dear José,
Here is one way:
# aux. function
foo <- function(x, ...){
m <- mean(x, ...)
S <- sd(x, ...)
x > m + S
}
# result
iris$rule <- with(iris, ave(Petal.Width, list(Species), FUN = foo))
head(iris)
HTH,
Jorge.-
On Thu, May 3, 2012 at 5:19 PM, Jose Bustos Melo <> wrote:
> Hi everyone,
>
> I would like to identify the case by groups that is just bigger that
> avg plus sd. For example, using species as group and petal.wid as my
> variable in the iris data.
> What's the better way to doit? creating a function?
>
> So,the question is to identify the single element of each species that is
> just larger than a cut-off point (i.e. larger than mean + sd)
> I made this, but I can not make a relation to to orginal data for
> identifiying the cases.If you have some lights please share it.
>
> data(iris)
>
> library(plyr)
> petal.wid.avg <-ddply(iris,.(Species),function(df)
> return(c(petal.wid.avg=mean(df$Petal.Width),petal.wid.sd
> =sd(df$Petal.Width)))
> )
> petal.wid.avg$avgsd <-petal.wid.avg$petal.wid.avg +petal.wid.avg$
> petal.wid.sd
> petal.wid.avg
>
>
> Thanks in advance:
> José
> [[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]]