R 查找重叠范围和
我有两个数据帧,其中包含两个范围内报告的变量:mzmin、mzmed、mzmax、rtmin、rtmed和rtmax。是:R 查找重叠范围和,r,range,intervals,R,Range,Intervals,我有两个数据帧,其中包含两个范围内报告的变量:mzmin、mzmed、mzmax、rtmin、rtmed和rtmax。是: table1 <- read.csv("table1.csv") name mzmed mzmin mzmax rtmed rtmin rtmax M1 202.1110 202.110859 202.111285 50.35 49.62 51.13 M2
table1 <- read.csv("table1.csv")
name mzmed mzmin mzmax rtmed rtmin rtmax
M1 202.1110 202.110859 202.111285 50.35 49.62 51.13
M2 373.144219 373.143792 373.154876 50.38 49.62 51.86
M3 371.14497 371.144256 371.145224 80.34 79.62 81.41
M4 372.147279 372.146992 372.147583 100.35 99.62 101.41
table2 <- read.csv("table2.csv")
name mzmed mzmin mzmax rtmed rtmin rtmax
M1 558.109976 558.102886 558.111497 10.89 9.95 11.95
M2 371.144564 371.144000 371.144999 80.29 79.14 81.98
M3 498.091821 498.091632 498.092225 658.15 656.57 660.96
M4 284.098785 284.098429 284.099092 760.32 758.67 761.2
表1正如Uwe Block所评论的,foverlaps是有效的
table1 <- data.table(read.table(header = T,
text = "name mzmed mzmin mzmax rtmed rtmin rtmax
M1 202.1110 202.110859 202.111285 50.35 49.62 51.13
M2 373.144219 373.143792 373.154876 50.38 49.62 51.86
M3 371.14497 371.144256 371.145224 80.34 79.62 81.41
M4 372.147279 372.146992 372.147583 100.35 99.62 101.41
"))
table2 <- data.table(read.table(header = T,
text = "name mzmed mzmin mzmax rtmed rtmin rtmax
M1 558.109976 558.102886 558.111497 10.89 9.95 11.95
M2 371.144564 371.144000 371.144999 80.29 79.14 81.98
M3 498.091821 498.091632 498.092225 658.15 656.57 660.96
M4 284.098785 284.098429 284.099092 760.32 758.67 761.2
"))
setkey(table2, mzmin, mzmax)
out <- foverlaps(table1, table2, type="any",nomatch=0L)
> out
name mzmed mzmin mzmax rtmed rtmin rtmax i.name i.mzmed i.mzmin i.mzmax i.rtmed i.rtmin i.rtmax
1: M2 371.1446 371.144 371.145 80.29 79.14 81.98 M3 371.145 371.1443 371.1452 80.34 79.62 81.41
table1可能,foverlaps()
来自数据。table
包可能适合您。
out[abs(mzmin-rtmax)<100 | abs(rtmin-mzmax)<100,]
Empty data.table (0 rows) of 14 cols: name,mzmed,mzmin,mzmax,rtmed,rtmin...