I have a data like this
name col1 col2 col3
1 a 43.78 43.80 43.14
2 b 43.84 43.40 42.85
3 c 37.92 37.64 37.54
4 d 31.72 31.62 31.74
lets call it df
df<-structure(list(name = structure(1:4, .Label = c("a", "b", "c",
"d"), class = "factor"), col1 = c(43.78, 43.84, 37.92, 31.72),
col2 = c(43.8, 43.4, 37.64, 31.62), col3 = c(43.14, 42.85,
37.54, 31.74)), class = "data.frame", row.names = c(NA, -4L
))
now I want to calculate the R2 and adjusted R2 between row d and the other rows
If I want to see all combinations, I can do the following for correlation
out <- cor(t(df[, -1]))
out[upper.tri(out, diag = TRUE)] <- NA
rownames(out) <- colnames(out) <- df$name
out <- na.omit(reshape::melt(t(out)))
out <- out[ order(out$X1, out$X2), ]
which gives me this
X1 X2 value
5 a b 0.8841255
9 a c 0.6842705
13 a d -0.6491118
10 b c 0.9457125
14 b d -0.2184630
15 c d 0.1105508
but I only want between row d and the rest and also I want to have both correlation coefficient and adjusted R2