首页 > 解决方案 > 如何在不删除行中的其余数据的情况下获得相交的行名

问题描述

我正在查看的数据并非都具有相同的行名值。其中一些基因在其他数据集中没有表达。如何使用 reduce(intersect, list(a,b,c)) 来选择常见的行名以及相应的列值?

我试过使用

Reduce(intersect, list(data.UT, c_data.MT, c_data.HT)) 

,但这只会输出常见的行名。

e2.Matrix <- matrix(nrow = 130, ncol = 15)
e3.Matrix <- matrix(nrow = 339, ncol = 15)

# read in the datasets

df.UT<- read.csv("05.08.19.UT_AdultVInfant.wadjp.csv", header= TRUE, 
row.names= NULL)

# change header to TRUE if comparing condition bound by columns
# change header to FALSE if comparing condition bound by rows
df.MT<- read.csv("05.15.19.MT_AdultVInfant.wadjp.csv", header= TRUE, 
row.names= NULL)

# change header to TRUE if comparing condition bound by columns
# change header to FALSE if comparing condition bound by rows
df.HT<- read.csv("05.15.19.HT_AdultVInfant.wadjp.csv", header= TRUE, 
row.names= NULL)

# convert dataframes to matrices so we can combine them with the empty matrices

data.matrix(df.UT[,2:15])
data.matrix(df.MT[,2:15])
data.matrix(df.HT[,2:15])
data.UT <- cbind(data.matrix(df.UT$gene), data.matrix(df.UT[,2:15]))
data.MT <- cbind(data.matrix(df.MT$gene), data.matrix(df.MT[,2:15]))
data.HT <- cbind(data.matrix(df.HT$gene), data.matrix(df.HT[,2:15]))

# data,UT is the laregest matrix so it does not extra rows
# bind the smaller matrices so all are same length

c_data.MT <- rbind(data.MT, e2.Matrix)
c_data.HT <- rbind(data.HT, e3.Matrix)

# this script will select only the gene that are shared amongst the 3 condition
# view the new data frame
# export the data frame to a text editor to make list of genes to select for in filter

View(Reduce(intersect, list(data.UT, c_data.MT, c_data.HT)))

这是我得到的输出

[1] "AC009234.1" "ACSL5"      "ADAMTS15"   "ALDH3A1"    "ANKRD45"    
"CES1P1"     "CES1P2"    
 [8] "COL4A1"     "COL4A2"     "COL5A2"     "CYP2A6"     "CYP2A7"     
"CYP2A7P1"   "CYP2B6"    
[15] "CYP2C18"    "MRC2"       "SCGB3A1"    "0"

但是列应该有相应的值

标签: r

解决方案


推荐阅读