I'm writing codes for Prisoners' Dilemma in R, and am blocked in creating the payoff matrix. Wonder if there is a way to create a python dictionary like array or a matrix whose elements are tuples. Thus this matrix should represent the gains of both players:
Here is the image:
This image is only to show you what I'm up to, and the values are different from the matrix I want to create. I try to create lists and then assign them to the matrix but it only assigns the first element of lists to the matrix. This is my code snippet:
T=2
R=1
P=0
S=-1
act1 <- as.vector(list(T,S), mode="pairlist")
act2 <- as.vector(list(P,P), mode="pairlist")
act3 <- as.vector(list(R,R), mode="pairlist")
act4 <- as.vector(list(S,T), mode="pairlist")
actions <- c(act3,act4,act1,act2)
payoff.mat <- as.matrix(actions,nrow=2,ncol=2)
dimnames(payoff.mat)[[1]] <- c("Gift","NoGift")
dimnames(payoff.mat)[[2]] = dimnames(payoff.mat)[[1]]
Any Idea of how to do this?