There are balls with values 1 to 3 in the bag. I will draw all three ball without replacement at random. For the first ball, I need to pay the value of the ball multiplied by 1. For the second ball, I need to pay the value of the ball multiplied by 2. For the third ball, I need to pay the value of the ball multiplied by 3. For example, if you drew 1,2,3, then your total payment is (1*1)+(2*2)+(3*3) = 14. I want to find the mean of all possible total payments.
So I had this code:
library(gtools)
N<-1:3
perms3 <- data.frame(permutations(n = 3, r = 3, v = N))
perms3$total_payment <- perms3$X1 *1+ perms3$X2*2 + perms3$X3*3
mean(perms3$total_payment)
I would like to make the general function that I can apply to any number of N. For example, there are balls with values 1 to 5 or 1 to 10 and so on.
I might use above code with a little manipulation to calculate the mean of total payment like this:
N<-1:5
perms5 <- data.frame(permutations(n = 5, r = 5, v = N))
perms5$total_payment <- perms5$X1 *1+ perms5$X2*2 +perms5$X3*3 +perms5$X4*4 +perms5$X5*5
mean(perms5$total_payment)
But, I don't want to do that each time. Can you help me solve this problem?