[R] Extracting means for given strata from dissimilarity object

Martin Maechler maechler at stat.math.ethz.ch
Wed Jan 8 14:08:58 CET 2003

>>>>> "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

give the overall statistics; 
for "individual ones", use as.matrix() and apply(), as

## e.g.,
am <- apply(as.matrix(iris.dist), 2, mean)
          apply(as.matrix(iris.dist), 1, mean) ## -> TRUE

Martin Maechler <maechler at stat.math.ethz.ch>	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			<><

More information about the R-help mailing list