Reputation: 337
I have two distinct tables and want to find correlation between GeneQ in table2 and other Genes in table1 across 6 samples. How can I calculate and visual this correlation in R?
Thanks for any help.
Here is my table1
> dput(df1)
structure(list(Gene.name = c("GeneA", "GeneB", "GeneC", "GeneD"
), Sample1 = c(150L, 49L, 136L, 158L), Sample2 = c(322L, 13L,
378L, 301L), Sample3 = c(84L, 95L, 66L, 75L), Sample4 = c(79L,
86L, 71L, 63L), Sample5 = c(26L, 111L, 21L, 32L), Sample6 = c(103L,
29L, 112L, 109L)), class = "data.frame", row.names = c(NA, -4L
))
> df1
Gene.name Sample1 Sample2 Sample3 Sample4 Sample5 Sample6
1 GeneA 150 322 84 79 26 103
2 GeneB 49 13 95 86 111 29
3 GeneC 136 378 66 71 21 112
4 GeneD 158 301 75 63 32 109
And table 2
> dput(df2)
structure(list(Gene.name = "GeneQ", Sample1 = 52L, Sample2 = 18L,
Sample3 = 89L, Sample4 = 77L, Sample5 = 118L, Sample6 = 36L), class = "data.frame", row.names = c(NA,
-1L))
> df2
Gene.name Sample1 Sample2 Sample3 Sample4 Sample5 Sample6
1 GeneQ 52 18 89 77 118 36
Upvotes: 0
Views: 52
Reputation: 405
You can try something like
apply(df1,1,function(x) cor(as.numeric(x),as.numeric(df2)))
Upvotes: 0