I am trying to make columnwise calculations. The goal is to compute an index (IX) for for every player (r001,r002,r003), over every gameround (row).
#the data frame looks like this:
df <- data.frame(gameround= c("1_1", "1_2", "1_3"),
r001 = c(3,5,4), r002 = c(2,3,5), r003 = c(1,2,2), weight001=c(0.7,0.8,0.7),
weight002 = c(0.6,0.1,0.6), weight003=c(0.2,0.7,0.2),
FORMULA = c("PosdownNegUp", "NegdownPosUp", "PosdownNegUp"),
IXsum = NA)
#There are two different formulas:
#FORMULA PosdownNegUp:
#if r001 is 1, take weight001*1.
#if r001 is 2, take weight001*0.5.
#if r001 is 4, take weight001*-0.5.
#if r001 is 5, take weight001*-1.
#IXSUM = repeat for every r00 and take the sum per gameround.
#FORMULA NegdownPosUp:
#if r001 is 1, take weight001*-1.
#If r001 is 2, take weight001*-0.5.
#if r001 is 4, take weight001*0.5.
#if r001 is 5, take weight001*1.
#IXSUM = repeat for every r00 and take the sum per gameround.
#Player scores of 3 or 0 should not be included in the IXsum calculation.
#the result should look like this:
df
# gameround r001 r002 r003 weight001 weight002 weight003 FORMULA IXsum
# 1_1 3 2 1 0.7 0.6 0.2 PosdownNegUp 0.5 # = (0.6*0.5)+(0.2*1)
# 1_2 5 3 2 0.8 0.1 0.7 NegdownPosUp 0.45 # (0.8*1)+(0.7*-0.5)
# 1_3 4 5 2 0.7 0.6 0.2 PosdownNegUp -0.85 # = (0.7*-0.5)+(0.6*-1)+(0.2*0.5)
I'd be extremely grateful if anyone could help me out!