That works nicely.

Thank you.


jim holtman <jholtman@gmail.com> wrote: try this:
  
  
trim <- function(x,prop=.05) {
    trimlow <-quantile(x,prob=(prop))
    trimhigh <- quantile(x,prob=(1 - prop))
    x[(x >= trimlow) & (x <= trimhigh)]
}
  


 
 On 3/20/07, Jonathan Morse <asn151@yahoo.com> wrote: Thanks for the rapid response.

The inequality with the quantile trim works great, however I am in looking for a two tailed trim.  This could work if I could unite two series in a command similar to the following: 

trim <- function(x,prop=.05) {
trimlow <- x[x < quantile(x,prob=(1-prop))]
trimhigh <- x[x > quantile(x,prob=(prop))]
trimx <- intersect(trimlow, trimhigh)
return(trimx)
}

However the intersect function will not return repeated values, which is a problem.  Any thoughts?? 

Thanks.

Petr Klasterecky <klaster@karlin.mff.cuni.cz> wrote: If it is precise enough for you, you can use

trim <- function(x,prop=.05) {
trimx <- x[x < quantile(x,prob=(1-prop))] 
return(trimx)
}

Petr

Jonathan Morse napsal(a):
> Hi,
>
> I am trying to restrict a data set so as not to included outliers.  Specifically, I would like to specify a percentage where a fraction of observations are eliminated from the data set, much in the same way that the trimmed mean function works - but leaving the restricted data set intact. 
>
> I have been using a function which will restrict the data set using:
>> trim=function(x,p){
>> o=order(x)
>> xo=x[o]
>> n=length(xo)
>> tl=round(n*p)
>> print(xo[(tl+1):(n-tl)])} 
>
> However I was wondering if anyone knew a more elegant and simple method to get the same result.
>
> Thanks in advance.
>
>
>
> ---------------------------------
> Don't pick lemons. 
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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. 
>

--
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



---------------------------------
TV dinner still cooling?
Check out "Tonight's Picks" on Yahoo! TV. 
       [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch 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. 




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?  

 
---------------------------------
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
	[[alternative HTML version deleted]]

