[R] Applying boxplot.stats to multiple value lists

Peter Ehlers ehlers at ucalgary.ca
Tue May 24 00:51:39 CEST 2011


On 2011-05-23 07:40, Rashid Bakirov wrote:
>
> Hello all R gurus,
>
> I have a following problem which I hope someone will help me to solve.
>
> I have a data.frame in form similar to below.

>  testframe<-data.frame("Name"=c("aa","aa","aa","aa","aa","bb","bb","bb","bb","bb"),"Value"=c(1,100,1,1,1,100,100,100,100,1))
>       Name Value
> 1    aa     1
> 2    aa   100
> 3    aa     1
> 4    aa     1
> 5    aa     1
> 6    bb   100
> 7    bb   100
> 8    bb   100
> 9    bb   100
> 10   bb     1
 > > My aim is to find extreme upper whisker of boxplot 
(boxplot.stats$stats[5]) of Values
> for each unique Name.I wrote the folowing function for this
 >
 > upex<-function(x){boxplot.stats(subset(testframe, Name==x, 
select=Value))$stats[5]}
 > When I test with different strings it works correctly>  upex("bb")
[... snip ...]

Try the plyr package:

  require(plyr)
  ddply(testframe, .(Name), function(x) {
            boxplot.stats(x[["Value"]])[["stats"]][5]})


Peter Ehlers



More information about the R-help mailing list