Homework Problem Set 3, Due Wednesday September 14, 2016. -------------------------------------------------------- Assigned 9/7/2016, due 9/14 (a) Define and test an R function "framfix" which takes as a single argument a data-frame (infram) and does the following: (o) it coerces all boolean columns to numeric, and then: (i) it changes all missing (NA) values in numeric columns to 0; (ii) it tabulates the numbers of distinct values of each character column, and puts this into a vector; and tabulates the frequencies of the different values for each character column, and puts this information into a list with number of components equal to the number of character columns; and (iii) it tabulates means and variances of the numeric columns into a Kx2 matrix, where K = number of numeric columns. The output should be a list (with appopriately named components). (b) Suppose you are given a 3-way array Xarr and want to compute the 2-dimension array: ( sum_{j,k} Xarr[i,j,k]*Xarr[i',j,k] )_{i,i'} indexed by i,i'. That is, the indices i,i' are the row-column indices of the resulting matrix (2-way array), and the summation is over all levels of the j,k indices which are the 2nd and 3rd dimension indices in the array Xarr[i,j,k]. So the operation you are doing is filling a matrix indexed by all possible values of i and i' in {1,...,I} and for each such fixed pair of i,i' you are computing the resulting matrix element as the sum over all j=1,...J and k=1,...K of the products Xarr[i,j,k]*Xarr[i,j,k]. Here the dimension of the 3-way array Xarr is being denoted as IxJxK. Do this inside a function, in two ways: (1) using a for-loop on indices j,k, and (2) using vector/matrix commands. [Hint: the second way may involve re-formatting 3-way arrays into 2-way arrays !] Also inside the same function, insert code to record the system.time taken by the two methods of calculation. Give the code for your function, and do some tests on small arrays to show that your function computes correctly on small 3-dim arrays. Finally, apply your function to the array array(runif(8e6), c(200,160,250) ) and verify that your two ways of computing the output 300 x 300 give the same result (to within your machine accuracy).