[R] write a function to do pairwise calculation

arun smartpink111 at yahoo.com
Tue Jun 18 00:09:15 CEST 2013


Hi, 

You didn't provide any information about the package.  I guess it is from "energy".  


library(energy)
x <- iris[1:50, 1:4]   #examples given in the package
y <- iris[51:100, 1:4]
z<- iris[101:150,1:4]
vec1<-c("x","y","z")
mat1<- combn(vec1,2)

sapply(split(mat1,col(mat1)),function(.dat) dcor(get(.dat[1]),get(.dat[2]),1.5))
#        1         2         3 
#0.1862890 0.2331567 0.2303689 


A.K.





----- Original Message -----
From: Amanda Li <amandali at uchicago.edu>
To: r-help at r-project.org
Cc: 
Sent: Monday, June 17, 2013 1:14 PM
Subject: [R] write a function to do pairwise calculation

Hello,

I want to write a function to do pairwise calculation, but I don' know how
to write it. Could anyone help?

i.e. I have A (2*3), B(3*3), C(4*3) three matrices. I want to calculate
distance correlation between each pair of matrices using code "dcor". How
do I write a function so that I can get the result as a matrix integrating
all the  pairwise results?

Thanks in advance for your help!

Best,
Amanda

    [[alternative HTML version deleted]]

______________________________________________
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.




More information about the R-help mailing list