Given two [n,2] matrices I would like to compare them, like in the following example:
library('fastmatch')
Matrix2Curt=cbind(c(1,2,3,4),c(5,6,7,8))
Matrix2compare=cbind(c(1,2,3,4,5,6,7,3,9),c(5,1,2,3,3,9,3,7,6))
a=lapply(split(Matrix2compare,row(Matrix2compare)),as.numeric)
b=lapply(split(Matrix2Curt,row(Matrix2Curt)),as.numeric)
RmRowIndex=fmatch(a,b)
IndexInMatrix2comp<-which(!is.na(RmRowIndex))
RmRowIndex=na.omit(RmRowIndex)
OpenPositions=Matrix2Curt[-RmRowIndex,]
FoundPositions=Matrix2compare[IndexInMatrix2comp,]
I need a lot of this kind of computations in a bigger Algorithm and 90% of running time is put in the above lines. Does someone know a faster way to calculate this?
Thank you for your help
Remarks on comments: Yes, I put the Code in a function called setdiffMatrix() and called this function a few times:
$by.self
self.time self.pct total.time total.pct
".Call" 1.76 84.62 1.76 84.62
"lapply" 0.14 6.73 0.32 15.38
"as.character" 0.10 4.81 0.10 4.81
"as.factor" 0.02 0.96 0.16 7.69
"eval" 0.02 0.96 0.02 0.96
"FUN" 0.02 0.96 0.02 0.96
"match" 0.02 0.96 0.02 0.96
$by.total
total.time total.pct self.time self.pct
"setdiffMatrix" 2.08 100.00 0.00 0.00
".Call" 1.76 84.62 1.76 84.62
"fmatch" 1.76 84.62 0.00 0.00
"lapply" 0.32 15.38 0.14 6.73
"as.factor" 0.16 7.69 0.02 0.96
"split" 0.16 7.69 0.00 0.00
"split.default" 0.16 7.69 0.00 0.00
"as.character" 0.10 4.81 0.10 4.81
"eval" 0.02 0.96 0.02 0.96
"FUN" 0.02 0.96 0.02 0.96
"match" 0.02 0.96 0.02 0.96
"match.arg" 0.02 0.96 0.00 0.00
"sort" 0.02 0.96 0.00 0.00
"sort.default" 0.02 0.96 0.00 0.00
"sort.int" 0.02 0.96 0.00 0.00
$sample.interval
[1] 0.02
$sampling.time
[1] 2.08