Thanks Martin. This gives me some ideas, but doesn't quite solve my problem of getting the mean within-species distances (perhaps I hadn't expressed that clearly enough). I'm thinking in lines of something like:
tapply(as.matrix(iris.dist), iris$Species, mean) except that that doesn't work, because the arguments don't have the same length and I don't really want to include the dissimilarities of an individual on to itself (always zero) in the calculation. In real examples I would often use geographical units as the group that I want the within-group mean for, as a measure of morphological diversity within the unit. Any ideas on how to solve this would be greatly appreciated. Mikkel -----Original Message----- From: Martin Maechler [mailto:[EMAIL PROTECTED]] Sent: 08 January 2003 16:07 To: Grum, Mikkel [IPGRI-SSA-Nairobi] Cc: [EMAIL PROTECTED] Subject: Re: [R] Extracting means for given strata from dissimilarity object >>>>> "MGrum" == Grum, Mikkel [IPGRI-SSA-Nairobi] <Grum> >>>>> on Tue, 07 Jan 2003 03:51:38 -0800 writes: MGrum> Is there a way of extracting mean distance or MGrum> dissimilarity for a given strata from a 'dist' or MGrum> 'dissimilarity' object, e.g. extract mean distances MGrum> for each species in Anderson's iris data? MGrum> data(iris) MGrum> iris.dist<-dist(iris[,1:4]) MGrum> then what? mean(iris.dist) # or summary(iris.dist) give the overall statistics; for "individual ones", use as.matrix() and apply(), as ## e.g., am <- apply(as.matrix(iris.dist), 2, mean) identical(am, apply(as.matrix(iris.dist), 1, mean) ## -> TRUE Martin Maechler <[EMAIL PROTECTED]> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
