View the step-by-step solution to:

USE R: Here we will be interested in permutations , which are like combinations but with all possible orderings. For instance, suppose we are looking...

USE R:


Here we will be interested in permutations, which are like combinations but with all possible orderings. For instance, suppose we are looking at subsets of 1,2,...,8, taken two at a time. Corresponding to the combination (2,7), the permutations are (2,7) and (7,2). For the combination (1,2,7), the permutations are (1,2,7), (2,1,7), (1,7,2), (7,2,1), (7,1,2) and (2,7,1).

  1. please help me to find a functions with call form
permn(x,m,FUN)
  1. analogous to combn() but for permutations. FUN (which has no default, i.e. cannot be NULL) is applied to each permutation, so that permn()returns a vector consisting of the values of FUN at the various permutations of x taken r at a time.
  2. You will NOT be required to save memory, i.e. if you wish, you can have your permn() first generate all permutations, then call FUN() on each one. However, FUN must be an argument of permn(), as above.
  3. There are permutation generators in the partitions and gtools packages, available on CRAN.
  4. Example:
first <- function(z) z[1]
permn(7:10,2,first)
 [1]  7  8  7  9  7 10  8  9  8 10  9 10

b) Apply your permn() to solve the following problem. We choose 8 numbers, X1,...,X8 from 1,2,...,12. We are interested in the quantity W = Σi=17|Xi+1 - Xi|. Find EW. (Note: This is an exact value, but it is recommended that you check via simulation.)

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question