I used the following code to make a table of Spearman Rho correlations for a CSV file with 2+ columns in R:
> myDataset <- read.csv(file.choose())
> attach(myDataset)
> spearmanRhoTestData <- cor(myDataset, use="complete.obs",method="spearman")
However, in my table (spearmanRhoTestData), the correlation between any two variables will show up twice (like the following):
Var1 Var2 Var3 Var4
Var1 1 0.5 0.7 0.9
Var2 0.5 1 0.3 0.6
Var3 0.7 0.3 1 0.2
Var4 0.9 0.6 0.2 1
Is there any way I could write code in R to get rid of the correlation values (ex: between var1 and var2) from showing up twice in the entire table??
dput(head(my_data,10))
for instance. - NelsonGonspearmanRhoTestData[upper.tri(spearmanRhoTestData)] = NA; spearmanRhoTestData
.This will replace all the upper triangle part of the matrix withNA
s. - AntoniosK= ""
will update your values from numeric to character, in order to match the""
value. You might face some difficulties if you want to further process your data. If it's just for viewing / presentation purposes it's OK. :) - AntoniosK