简体   繁体   English

跨行和列的R cor

[英]R cor across rows and columns

Hello I currently have a matrix that has genes as row.name and Tissue Type as colnames. 您好,我目前有一个矩阵,其基因为row.name,组织类型为colnames。 If I: 如果我:

> cor(matrix)
> str(DataCor2)
 num [1:39453, 1:19] 0.502 7.974 33.462 0 14.543 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:39453] "AC205376.4_FG003" "GRMZM2G024563" ...
  ..$ : chr [1:19] "V18_Meotic_TasselR1" "V18_Meotic_TasselR2" ...

I get a correlation between tissue types. 我得到了组织类型之间的关联。 What I want to do is get a correlation of a subsets of genes across each tissue type for a heat map, I tried: 我想做的是获取每种组织类型的基因子集与热图的相关性,我尝试过:

cor(v, t(v)) cor(v,t(v))

But I get an error saying incompatible dimensions. 但是我收到一个错误的消息,说尺寸不兼容。 Here is part of the data and I want to see a correlation of expression levels between genes across tissue types. 这是数据的一部分,我希望了解各种组织类型之间基因之间表达水平的相关性。 The heat map would look similar to the matrix with genes on the Y axis and tissue on the X axis. 热图看起来类似于在Y轴上有基因,在X轴上有组织的矩阵。 Hopefully it makes more sense. 希望它更有意义。

在此处输入图片说明

Suppose you want to subset the genes based on the prefix and do the cor on each subset 假设你要subsetgenes基础上的prefix并做cor上的每个subset

 res <- lapply(split(1:nrow(mat1), gsub("_.*", "", rownames(mat1))),
                               function(i) cor(mat1[i,]))

data 数据

set.seed(29)
mat1 <- matrix(sample(0:80, 15*3, replace=TRUE), ncol=3,
   dimnames=list(paste(rep(c('V18', 'V19'), c(8,7)), LETTERS[1:15],
   sep="_"), paste0("AC", 1:3))) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM