I want to calculate mean of reward for each gamble and create a new column based on that. for example, this is my data:
gamble<-c(1,2,3,4,2,3,4,1)
reward <- c(1,0.5,0.5,0.4,0.5,0.4,0.2,0.5)
new<-data.frame(gamble, reward)
and the new column should look like this:
gamble reward newcolumn
1 1.0 0.75
2 0.5 0.50
3 0.5 0.45
4 0.4 0.30
2 0.5 0.50
3 0.4 0.45
4 0.2 0.30
1 0.5 0.75
thank you very much in advance... i am really confused...