【发布时间】:2015-11-20 13:46:44
【问题描述】:
我在这里和谷歌搜索了几个小时,但找不到解决我的问题的方法。
我有两个包含基因的数据集。一个数据集是我的数据集(快照),我需要查看这些基因是否在第二个更大的数据集(目录)中。我想要 snap(代理)中的第二列和目录中的第 21 列。这就是我的数据集的样子;
> head(snap)
SNP Proxy Distance RSquared DPrime
1 rs4246511 rs7540233 4541 0.874 1
2 rs4246511 rs4970634 15768 0.874 1
3 rs4246511 rs4532801 18960 0.874 1
4 rs4246511 rs9438982 22242 0.874 1
5 rs4246511 rs9438979 25034 0.874 1
6 rs4246511 rs4414011 25868 0.874 1
head(catalog)
SNPS MERGED SNP_ID_CURRENT CONTEXT INTERGENIC
1 rs7079041 0 7079041 intron 0
2 rs7244261 0 7244261 intergenic 1
3 rs10448044 0 10448044 intergenic 1
4 rs2610025 0 2610025 intergenic 1
5 rs1472147 0 1472147 intron 0
6 rs2648708 0 2648708 intron 0
*这是数据集的一小部分
为了让它更复杂,我还希望能够从两个数据集中提取整行数据。
对于我的问题的第一部分,我尝试过使用比较(我从另一个类似的问题中找到的)。我决定提取我需要的列来简化事情(proxy 是我的 snap 列,catalogsnps 是 catalog 中的列);
comparison <- compare(proxy, catalogsnps, allowAll=TRUE)
comparison$tM
difference <- data.frame(lapply(2:ncol(proxy),function(i)setdiff(cacheGenericsMetaData[,i],comparison$tM[,i])))
colnames(difference) <- colnames(proxy)
write.table(difference, file="difference.csv", sep=";", dec=".")
但是,使用这种语法,我的输出只是我所有来自 snap 的 SNP 的列表。
输出
1054 6267
1055 6273
1056 6297
1057 6297
1058 6314
1059 6331
1060 6340
1061 6345
1062 6346
1063 6350
1064 6364
1065 6412
1066 6417
1067 6417
1068 6430
由于这很难阅读,我添加了获取excel文件的行,如下所示;
x
1 rs7079041
2 rs7244261
3 rs10448044
4 rs2610025
5 rs1472147
6 rs2648708
7 rs11891
8 rs1801725
9 rs6852678
10 rs3135758
11 rs6838240
12 rs6838240
13 rs603894
14 rs3764796
15 rs3764796
16 rs2073214
17 rs4971100
18 rs4971100
19 rs11718502
20 rs10888073
21 rs7032317
我还在这里找到了另一种可能的解决方案,但我再次只得到了我的 SNP 列表。
rows.diff <- function(catalog, proxy)
{
catalogsnps.vec <- apply(catalogsnps, 1, paste, collapse="")
proxy.vec <- apply(proxy, 1, paste, collaspse= "")
rows.diff <- catalogsnps[!catalogsnps.vec %in% proxy.vec,]
return(rows.diff)
}
write.table(rows.diff(catalogsnps, proxy), file="rowdiff.csv", sep=";", dec=",")
对于我的问题的第二部分,我完全不知道从哪里开始
非常感谢您的帮助
克莱尔
【问题讨论】:
-
您能否在此问题中添加一些数据示例输出
dput(head(proxy)) -
我已经用输出编辑了我的帖子,我想这就是你的意思吗?
-
没有克莱尔,他要求输出他给出的代码。这是一种共享要读入 R 的输入数据样本的方法。
-
Claire 很接近,但是对于查看您的问题的人们会有帮助的是您尝试比较的数据框中的行和列中的数据样本。 dput 函数将允许其他人使用您的数据,但如果您可以包含来自每个数据集
head(snap)和head(catalog)的示例,它将让我们更好地指示您正在使用的数据和您的元素正在尝试比较 -
嗯,好的,我已经添加了,谢谢