Combinations in R
The general formula for finding a combination in R
is:
choose(n, k)
Go back to this example:
Ex: Stock Portfolio
Suppose there are 100 possible stocks
Link to original
- You want to invest equally in five stocks (20% in each). How many possible portfolios are there? (Order doesn’t matter here)
- You want to form a 30%/25%/20%/15%/10% weighted portfolio of five stocks. How many possible portfolios are there? (Order does matter here)
If finding the first bullet point, where order doesn’t matter:
choose(100, 5)
Permutations in R
No built in function for permutations, but its very simple, because the equation for permutations itself is simple.
Recall the Permutation general formula:
Link to originalP_{n,k}=\frac{n!}{(n-k)!}
We can express this in R
as:
factorial(n)/factorial(n-k)
Normal Distribution in R
dnorm(x, mean, sd)
can be used to find the PDF of a normal random variable given the standard deviation and mean. It defaults to the PDF for
pnorm(x, mean, sd)
can be used to find the PDF of a normal random variable given the standard deviation and mean, it defaults to the CDF for