How to apply a function for Spearman's rank correlation coefficient in R?
<p>I want to write a code for applying the fuction calculating the Spearman's rank correlation between combinations of column from a dataset. I have the following dataset:</p>

<pre><code>library(openxlsx)
data &lt;-read.xlsx("e:/LINGUISTICS/mydata.xlsx", 1);

A    B    C    D
go   see  get  eat
see  get  eat  go
get  go   go   get
eat  eat  see  see
</code></pre>

<p>The function <strong>cor(rank(x), rank(y), method = "spearman")</strong> measures correlation only between two columns, e.g. between A and B:</p>

<pre><code>cor(rank(data$A), rank(data$B), method = "spearman")
</code></pre>

<p>But I need to calculate correlation between all possible combinations of columns (AB, AC, AD, BC, BD, CD). I wrote the following function for that:</p>

<pre><code>wert &lt;- function(x, y) { cor(rank(x), rank(y), method = "spearman") }
</code></pre>

<p>I do not know how to implement all possible combinations of columns (AB, AC, AD, BC, BD, CD) in my function in order to get all results automatically, because my real data has much more columns, and also as a matrix with correlation scores, e.g. as the following table:</p>

<pre><code>    A     B     C     D
A   1     0.3   0.4   0.8
B   0.3   1     0.6   0.5
C   0.4   0.6   1     0.1
D   0.8   0.5   0.1   1
</code></pre>

<p>Can somebody help me?</p>