r - applying function to permutated objects -
i have, say, 20 objects. have function performs pairwise analyses. want pairwise analysis on pairs. let's function cor.test. rather write out 190 pairs
a <- cor.test(1,2); b <- cor.test(1,3); c <- cor.test(1,4) ...
how can apply function pairs @ 1 time , spit out, in case, correlations between each pair? advice appreciated.
(in case it's important, each object matrix)
you can utilize combn
, not clear how correlations between matrices, here how assuming have vectors:
## set objects within same list , can utilize `mget` if have ## pattern objects names ll <- list(obj1,obj2,obj3) ## combining permutations , applying function combn(seq_len(length(ll)),2,fun = function(x){ cor.test(ll[[x[1]]],ll[[x[2]]]) },simplify=false)
where objects :
obj1 = 1:5 obj2 = 1:5 obj3 = 1:5
r function permutation
No comments:
Post a Comment