- 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 1 (56.35 KiB) Viewed 36 times
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=
-
- Site Admin
- Posts: 899559
- Joined: Mon Aug 02, 2021 8:13 am
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=
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.