6. The sample function is useful for sampling from a vector. For example, if X <- c(1,2,3,4,5) then sample(x,3, replace=
Posted: Sun Oct 03, 2021 12:37 pm
6. The sample function is useful for sampling from a vector. For example, if X <- c(1,2,3,4,5) then sample(x,3, replace=FALSE) will randomly sample three elements from x without replacement, sample(x,3,replace=TRUE) will randomly sample three elements from x with replacement, and sample(x) will return a random permutation of the elements of x. Write R code that will randomly permute the rows of the data frame iris. 7. Write R code that will create the matrices [1 2 3 X = 4 5 6 and Y | 7 8 9 and perform the following computations. Note that the transpose of a matrix if found using the t function and the inverse of a matrix X is found as solve(x). (a) X'X+X (b) Y'XY (c) (X'X)-1 8. Using the recycling rules in R, show a simple way of creating the matrix - х without having to type in all of the entries.