Dear Steven,

Try this:

# Data set
yourdata=as.data.frame(cbind(lvl=LETTERS[1:2],x=rpois(10,10),y=rnorm(10) ))

# Splitting your data set
sdata=split(yourdata,yourdata$lvl)
res=lapply(sdata,function(X) max(dist(X[,-1])))
do.call(c,res)


HTH,

Jorge





On Wed, Aug 27, 2008 at 7:28 PM, Steven Matthew Anderson
<adastra69@mac.com>wrote:

> Thank you Jorge,
>
> My talent in building functions is weak.  I think I'm close but I'm not
> doing something right.
>
> res=dist(yourdata)
> res[which.max(res)]
> does provide me with the correct distance but how do I apply it across data
> with level such as ...
>
> > yourdata=as.data.frame(cbind(lvl=LETTERS[1:2],x=rpois(10,10),y=rnorm(10)
> ))
> > yourdata
>    lvl  x                  y
> 1    A 10   0.14377148075807
> 2    B  5 -0.117753598165951
> 3    A 14 -0.912068366948338
> 4    B 10  -1.43758624082998
> 5    A 16 -0.797089525071965
> 6    B 11   1.25408310644997
> 7    A  7   0.77214218580453
> 8    B  9 -0.219515626753440
> 9    A 12 -0.424810283377287
> 10   B 13 -0.418980099421959
>
> My attempt to use tapply blew up on me.
>
> > Extreme.Spread<-matrix(nrow=60,ncol=2)
> > ES<-function(Level) {
> +
> temp<-subset(x=ES.Data,Level==level,select=c(Horizontal,Vertical))
> +
> e<-dist(rbind(temp$Horizontal,temp$Vertical),method="euclidean")
> +                  m<-e[which.max(e)]
> +                  es<-cbind(level,m)
> +                  Extreme.Spread<-rbind(Extreme.Spread,es)
> +                  }
> > tapply(X=ES.Data,INDEX=Level,FUN=ES)
> Error in tapply(X = ES.Data, INDEX = Level, FUN = ES) :
>   arguments must have same length
>
>
>
>
>
> On Aug 27, 2008, at 2:30 PM, Jorge Ivan Velez wrote:
>
> R-help@r-project.org
>
>
> Steven Matthew Anderson
> AdAstra69@mac.com
>
> Ad Astra per Aspera
>
>
>
>

	[[alternative HTML version deleted]]

