r - 如何在不删除行中的其余数据的情况下获得相交的行名
问题描述
我正在查看的数据并非都具有相同的行名值。其中一些基因在其他数据集中没有表达。如何使用 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"
但是列应该有相应的值
解决方案
推荐阅读
- c++ - 如何将文件的特定部分读入私有数据成员
- android - 在 Wear OS 中的应用之间共享数据的最佳选择
- firebase - actionsdk 云功能的工作原理
- javascript - 当应用程序不使用或处于后台模式时,React Native 是否有函数生命周期正在运行?
- javascript - 对多个事件触发的操作
- python - 如何根据熊猫数据框中的条件移动列中的值
- angular - 测试角。TypeError:this._platformStrategy.getBaseHref 不是函数
- amp-html - 在用户同意的情况下控制嵌套 AMP 元素的解决方法
- python - 您如何指定对先前记录进行操作的 pandas groupby 操作?
- perl - perl 从哈希中提取多行