Exercise 1: Vectors

  1. Generate and print a vector of 10 random numbers between 5 and 500.
  2. Generate a random vector Z of 1000 letters (from “a” to “z”). Hint: the variable letters is already defined in R.
  3. Print a summary of Z in the form of a frequency table.
  4. Print the list of letters that appear an even number of times in Z.

Exercise 2: Matrices

  1. Create the following 5 by 5 matrix and store it as variable X.
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    6   11   16   21   26
[2,]    2    7   12   17   22   27
[3,]    3    8   13   18   23   28
[4,]    4    9   14   19   24   29
[5,]    5   10   15   20   25   30
  1. Create a matrix Y by adding an independent Gaussian noise (random numbers) with mean 0 and standard deviation 1 to each entry of X. e.g.

  2. Find the inverse of Y.

  3. Show numerically that the matrix product of Y and its inverse is the identity matrix.

Exercise 3: Data fames

  1. Create the following data frame and name it “exams”.
  1. Compute the mean score for this exam and print it.
  2. Find the student with the highest score and print the corresponding row of “exams”. Hint: use the function which.max().
LS0tCnRpdGxlOiAiTGVjdHVyZSAxOiBFeGVyY2lzZXMiCmRhdGU6IFNlcHRlbWJlciAyN3RoLCAyMDE4Cm91dHB1dDogCiAgaHRtbF9ub3RlYm9vazoKICAgIHRvYzogdHJ1ZQogICAgdG9jX2Zsb2F0OiB0cnVlCi0tLQoKIyBFeGVyY2lzZSAxOiBWZWN0b3JzCgoxLiBHZW5lcmF0ZSBhbmQgcHJpbnQgYSB2ZWN0b3Igb2YgMTAgcmFuZG9tIG51bWJlcnMgYmV0d2VlbiA1IGFuZCA1MDAuCjIuIEdlbmVyYXRlIGEgcmFuZG9tIHZlY3RvciBaIG9mIDEwMDAgbGV0dGVycyAoZnJvbSAiYSIgdG8gInoiKS4gSGludDogdGhlIAp2YXJpYWJsZSBgbGV0dGVyc2AgaXMgYWxyZWFkeSBkZWZpbmVkIGluIFIuCjMuIFByaW50IGEgc3VtbWFyeSBvZiBaIGluIHRoZSBmb3JtIG9mIGEgZnJlcXVlbmN5IHRhYmxlLgo0LiBQcmludCB0aGUgbGlzdCBvZiBsZXR0ZXJz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