4.3.5 How to do it with R
In the prob package, a probability space is an object space is an object of outcomes S and a vector of probabilities (called “probs”) with entries that correspond to each outcome in S. When S is a data frame, we may simply add a column called probs to S and we will be finished; the probability space will simply be a data frame which we may call S. In the case that S is a list, we may combine the outcomes and probs into a larger list, space; it will have two components: outcomes and probs. The only requirements we need are for the entries of probs to be nonnegative and sum (probs) to be one.
To accomplish this in R, we may use the probspace function. The general syntax is probspace (x,probs),where x is a sample space of outcomes and probs is a vector ( of the same length as the number of outcomes in x ). The specific choice of probs depends on the context of the problem, and some examples follow to demonstrate some of the more common choices.