I have a dataframe that has three variables: a, b, c. The first two columns in the data set are the pairing of two of the variables for all possible combinations and the third is the correlation between them. Shown below.
> var1 <- c("a","a","b")
> var2 <- c("b","c","c")
> r <- c(.55,.25,.75)
> as.data.frame(cbind(var1,var2,r))
var1 var2 r
1 a b 0.55
2 a c 0.25
3 b c 0.75
My question is whether it is possible to turn this dataframe containing the correlations into a correlation matrix object in R? I also want to use some of R's plotting and graphing functions.
Ultimately what I want is a matrix that looks like this
a b c
a 1 .55 .25
b .55 1 .25
c .25 .75 .75
xtabs(r ~ ., data=data.frame(var1,var2,r))
may get close depending on what you want exactly. If you could clarify I can adjust such an answer. – thelatemaila b c a 1 .55 .25 b .55 1 .75 c .25 .75 1
– Jean1213