I have a function in R that takes two vectors and an integer like this:
MyFunction<-function(MyLoot, DungeonLoot, DungeonOrder)
{
# Perfect Match
PerfectMatch = MyLoot[1]==DungeonLoot[1]
# Group Match
GroupandClassMatch = (MyLoot[2]==DungeonLoot[2])&(MyLoot[3]>=DungeonLoot[3])
# Order Match
OrderMatch = MyLoot[5]==DungeonOrder
# Order Match +1
OrderMatchPlusOne = (OrderMatch)&(MyLoot[8]==1)
# Final Score
Score = PerfectMatch*1 + GroupandClassMatch*1 + OrderMatch*2 + OrderMatchPlusOne*1
return(Score)
}
Now I want to apply MyFunction to two matrices Matrix1 and Matrix2 across their rows so that I have a vector that looks something like:
c(MyFunction(Matrix1[1,],Matrix2[1,],12),MyFunction(Matrix1[2,],Matrix2[2,],12),...,MyFunction[Matrix1[n,],Matrix2[n,],12)
What is the best (and most efficient) way of doing this? I could use a for loop but wondering if there is a better way e.g. using one of apply, sapply, mapply, lappy functions