meth
和exp
的行名分别与distal.dmr.cpgs
的probeID
和target_symbol
列匹配。我想根据distal.dmr.cpgs
的每一行中相同的probeID
和target_symbol
对的出现次数来复制meth
和exp
的行。
# Duplicate rows of `meth` and `exp` n-times, where n=#occurrence of `probeID` AND `target_symbol` pair
# `probeID` match `rownames(meth)`; `target_symbol` match `rownames(exp)`
n.occur <- distal.dmr.cpgs %>% count(probeID, target_symbol)
if(n.occur$probeID == rownames(meth)) {
for (n in n.occur$n){
meth <- meth[rep(seq_len(nrow(meth)), each=n), ]
exp <- exp[rep(seq_len(nrow(exp)), each=n), ]
}
}
追溯:
Error in if (n.occur$probeID == rownames(meth)) { :
the condition has length > 1
输入:
> dput(meth[1:5,1:5])
structure(c(0.965846994535519, 0.574436129165911, 0.8722836745901,
0.101103884990587, 0.408252566147303, 0.945927883796075, 0.480092866016333,
0.853431761902537, 0.0755436985006079, 0.448047437384109, 0.95713326619671,
0.8891500945397, 0.926905435737289, 0.203369962221719, 0.644251635185525,
0.961321856037767, 0.501968996835947, 0.865640773821373, 0.11543134872418,
0.472688968983197, 0.941828841874757, 0.484359313077939, 0.9011216776396,
0.155463949005687, 0.566371097999143), dim = c(5L, 5L), dimnames = list(
c("cg03477043", "cg00926926", "cg00488747", "cg04452095",
"cg04658243"), c("TCGA.Y8.A8S1.01", "TCGA.Y8.A8S0.01", "TCGA.Y8.A8RZ.01",
"TCGA.Y8.A8RY.01", "TCGA.Y8.A897.01")))
> dput(exp[1:5,1:5])
structure(c(8.8764930371619, 7.10418439636105, 5.82248600796462,
9.6336088827523, 7.12980348328146, 8.50488041264077, 7.4053080406626,
6.10447768176044, 9.82618201799457, 7.25526533976169, 8.91383556515162,
7.69822939472376, 6.293732617918, 10.0591928112391, 7.25510044887476,
8.05139916296298, 7.19502387866043, 6.05119750390752, 9.29733149115023,
7.55517805926009, 9.13478579142527, 7.38961451449646, 6.09188514895038,
9.67121455892562, 7.28978856899351), dim = c(5L, 5L), dimnames = list(
c("SRRM2", "ANKRD11", "RPTOR", "HSP90AA1", "RER1"), c("TCGA.2K.A9WE.01",
"TCGA.2Z.A9J1.01", "TCGA.2Z.A9J3.01", "TCGA.2Z.A9J5.01",
"TCGA.2Z.A9J6.01")))
> dput(distal.dmr.cpgs[,c("probeID","target_symbol")][1:5,])
structure(list(probeID = c("cg03477043", "cg03477043", "cg00926926",
"cg00926926", "cg00926926"), target_symbol = c("SRRM2", "SRRM2",
"ANKRD11", "ANKRD11", "ANKRD11")), row.names = c(785L, 786L,
866L, 867L, 868L), class = "data.frame")
预期输出:cg03477043
和SRRM2
的行将重复两次(在meth
和exp
中),而cg03477043
和SRRM2
将重复三次。
1条答案
按热度按时间b4lqfgs41#
将
meth
和exp
转换为 Dataframe ,以行名称作为列;列-将它们绑定到单个 Dataframe 中;并与distal.dmr.cpgs
连接以复制行。然后,您可以拆分成单独的 Dataframe ,或者作为单个 Dataframe 保留,这可能更有用。结果如下:
注意,这假设您希望保留
distal.dmr.cpgs
中没有匹配项的行;如果没有,请改用inner_join()
。