Given that we have
j<-c("a","b","c","d")
l<-expand.grid(j,j)
print(l)
Var1 Var2
1 a a
2 b a
3 c a
4 d a
5 a b
6 b b
7 c b
8 d b
9 a c
10 b c
11 c c
12 d c
13 a d
14 b d
15 c d
16 d d
I want to only return unique entries such as:
print(newl)
Var1 Var2
a a
a b
a c
a d
b b
b c
b d
c c
c d
d d
I have found a lot of answers where its unique combinations of variables, but where the variables do not cross over columns.
This all comes from doing corr.test {psych} and unrolling the corr.test$r into a single vector using as.vector(corr.test$r).
To get what correlations those are based off of I used
names<-expand.grid(rownames(corr.test$r),colnames(corr.test$r))
which ends up being consistent with the structure of the 'unrolled' r matrix from as.vector.
But it returns the whole matrix (both the upper and lower triangles). So I'm looking for a way to take only the unique correlations (half of the data.frame).