Final answer:
To generate the lifetime values of 50000 customers, a for loop and the sample() function in R can be used. The total spent for each customer can be calculated by multiplying the selected purchase and price. The values can be stored in a vector, and a histogram, summary statistics, and average lifetime value can be calculated.
Step-by-step explanation:
To generate the lifetime values of 50000 customers, we can use a for loop and the sample() function in R. First, we need to create a vector of possible purchases and a vector of possible prices. We can then use the sample() function within a for loop to randomly select a purchase and price for each customer.
The total spent for each customer can be calculated by multiplying the selected purchase and price. These values can be stored in a vector called lifetimevalue. Finally, we can create a histogram of the values using the hist() function and calculate the summary statistics and average lifetime value.