To Lecture Notes

CSC 433 -- May 15, 2017

Quiz 7

 

Review Exercises

  1. What does numeric(0) mean? What do you think numeric(n) means?
     
  2. How do you create a vector having length 0 of the following types: character, numeric, logical?
    Ans: v1 = character(0)  v2 = numeric(0)  v3 = logical(0).
     
  3. For the list xx defined by
    How do you access the items in a list by index?
    Ans: xx[[1]], xx[[2]], xx[[3]]
    Here is an interactive session:
  4. Create a list of 26 dataframes with one row each:
    Ans: Here is the script (improved from the one given in class):
  5. Redo the MyConcat example so that the myConcat function looks similar to the myCbind function for Project 5. Also write a function named runTimings that returns a dataframe containing the times for the slow function myConcat and the fast function c. Ans:
  6. Sort the rows of the dataframe from the Kids1 Example by (a) name, (b) age, (c) descending age, (d) gender, descending age, and name. Use the order function, not the sort function. Ans:
  7. Set up a plotting area like this. Then add these items to the plot:
     
    1. The points (2, 3), (5, 1), (8, 8) plotted with red plotting symbols pch=16.
       
    2. The polyline defined by (1, 9), (1, 1), (8, 8).
       
    3. The string "Start Point" centered at (2, 1).

    Ans:

  8. Try out the str and summary functions on a data frame created from kids1.txt.
    Ans: The str function shows the structure of an object:
    The summary function is similar. It summarizes the data in an object:
  9. An anonymous function is an R function that is not assigned a name like this:
    (The normal way to use such a function is like this:
    Give an example of where anonymous functions are useful in R.
    Ans: The apply function where you apply a function to rows of a matrix or dataframe.
     
  10. What does brushing mean when referring to statistical graphics? Look again at the BodyBrain Example.
    Ans: It means clicking on or mousing over points in a scatterplot to get more information about those points, such as observation numbers, labels, or corresponding points in other plots.
     
  11. True/False: you can create an R factor from numeric data.
    Ans: True. A factor represents categorical data. You can use numbers to represent categorical data.
     
  12. We will discuss this problem next week on May 22.

    Use R to compute the 0.63 quartile = Q(0.63) for the vector
    using methods 1 and 4. Verify your results by hand.
    Ans: First sort the vector:
    Compute the 0.67 quartile = Q(0.67) using Method 1:
    We have
     
    Index: 1 2 3 4 5
    Quantile: 0.2 0.4 0.6 0.8 1.0
    Value: x1=19 x2=21 x3=45 x4=76 x5=111

    To find the 0.67 quartile, note that 0.67 is between quantile 0.6 and 0.8 in the table--we round up to 0.8, so Q(0.67) = x4 = 76.
     
    Compute Q(0.67) using Method 4:
    Using the table above we see that Q(0.6) = x3 = 45 and Q(0.8) = x4 = 76. Use linear interpolation to find Q(0.67)
     
    interpolation diagram
     
    We use similar triangles:
     

    Check with R:
    Here is the R script that draws the interpolation diagram.
     
    See the Quantile Computations document for the details of computing quantiles of types 1 to 9.

 

R Graphics Parameters

 

Defining Your Own R Classes

 

R Date Objects

 

R Timeseries Objects

 

Functions Associated with Probability Distributions and Densities

 

A Simulated Bivariate Normal Dataset