Hi there!
I have 4 players, that are plying a game that have 6 "ideal" strategies. They can play variations of each strategy, so the plays does not match perfectly with how the strategy is, but i would like to add a column for the closest strategy that they are playing..
strategies<- data.frame(
name=c("strategy 1","strategy 2", "strategy 3","strategy 4","strategy 5","strategy 6"),
rebel=c(1,0,0,2,0,1),
cyber=c(0,1,3,0,0,2),
chrono=c(1,0,1,0,1,0),
void=c(0,0,0,1,0,0))
plays<- data.frame(
player=c("player 1","player 2","player 3","player 4"), rebel=c(1,0,3,NA),
cyber=c(1,NA,2,2),
chrono=c(1,1,0,3),
void=c(0,1,0,0))
What ineed to do is to grab player 1, compare him with each strategy and choose the strategy that is closer to the "ideal" one from "strategies" data frame. So i was thinking about
- calculating the difference between "player 1" play against each strategy (i would have one vector for each posible strategy)
- sum each number's absolute of that each vector
- Choose the strategy that has the min value, that means that is closer than the others.
For "player 1", it would be "strategy 1, since
- "player 1" -"strategy 1"= c(0,1,0,0).
- 0+1+0+0=1
- Strategy 1 has the min value, so its the closest strategy for "player 1"
There is any function that allows me to label every player's strategy with vectors?
I am not really good with vectors and I can not figure it out how to solve this without doing it manual.