[R] All possible combinations of functions within a function

jim holtman jholtman at gmail.com
Tue Nov 10 20:21:22 CET 2009


Here is a hint of how you might want to do the first part.  You might
want to study the 'lappy' function

vegList <- lapply(c('bray', ..., 'binomial'), function(.method){
    vegdist(x, method=.method)
})

clustList <- lapply(vegList, function(.dist){
    lapply(c('average', ..., 'centroid'), function(.dist){
        hclust(.veg, .dist)
    })
})

rest left as exercise for the reader.

On Tue, Nov 10, 2009 at 2:05 PM, bikemike42 <mlt35 at tamu.edu> wrote:
>
> Dear All,
>
> I wrote a function for cluster analysis to compute cophenetic correlations
> between dissimilarity matrices (using the VEGAN library) and cluster
> analyses of every possible clustering algorithm (SEE ATTACHED)
> http://old.nabble.com/file/p26288610/cor.coef.R cor.coef.R .  As it is now,
> it is extremely long, and for the future I was hoping to find a more
> efficient way of doing this sort of thing.
>
> To give you an outline of the function, first I create the  dissimiarity
> matrices using all possible methods in the VEGAN command "vegdist", then
> create the clusters using all possible algorithms in "hclust" and the
> dissimilarity matrices I crated, then create a table, and in one column,
> list all combinations, and in the other, compute and put the cophenetic
> correlation.
>
> Any help would be appreciated!  I'm pretty new to writing my own functions
> but I see great time-saving potential.
>
> Thanks!
> Mike
> --
> View this message in context: http://old.nabble.com/All-possible-combinations-of-functions-within-a-function-tp26288610p26288610.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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 that you are trying to solve?




More information about the R-help mailing list