To Lecture Notes

CSC 433 -- 5/8/17

Review Questions

  1. What does the attach function do?
    Ans: It allows the columns of a dataframe to be used as unqualified variables (it "attaches" the columns to the work space). For example:
    Use the detach function to detach the columns of the dataframe from the workspace. Always detach a dataframe when you are finished with it. Some programmers don't like the attach function. They say it makes R scripts harder to maintain.
     
  2. Write a script that produces a plot showing the plotting symbols corresponding to 1, 2, ... , 19.
  3. Show a plot that contains lines plotted with lty=1, ... , 6. Ans: Use this script:
  4. Give an example of an R nonatomic datatype.
    Ans: list, dataframe.
     
  5. What are attributes and how do you determine what they are for an R object? Ans:
    Ans: Attributes are pieces of data that can be added to an object. For example:
  6. List four ways of subsetting a vector, matrix, or data frame. Ans:
     
    1. Use positive indices to tell which rows or columns to keep:
      v[c(2, 4, 5)]   A[3, c(1, 3)]
       
    2. Use negative indices to tell which rows or columns to omit:
      v[c(-1, -3)]
        A[-(1:10), -6]
       
    3. Use a logical vector, where TRUE indicates which items to keep and FALSE indicates which items to omit:
      v[c(T, F, F, T, T)]
       
    4. Use the $ operator to indicate by name which column to keep, for example kids$age.
      k$age

  7. How do you delete a component from a list?
    Ans: Set that component to NULL:

  8. How can you give names to the components of a vector?
    Ans: Set the names attribute:

  9. What is an R replacement function?
    Ans: It is a function that can be called on the left side of the assignment operator <- to change the argument.  This is called return by reference in C++. For example:
  10. What are some commonly used arguments of the plot function? Ans:
    x, y, main, sum, xlab, ylab, xlim, ylim, col, pty
     
  11. Write a function named outliers that inputs a numeric dataframe with one column and returns the original dataframe with an added character column that indicates whether the data value in that row is an extreme outlier ("*"), mild outlier ("O"), or not an outlier (""). Ans:

 

Quiz 6

 

Functions that Input or Return Matrices

 

R String Handling Functions

 

Project 5b

 

More about Factors

 

Project 4b

 

Project 5

 

R Graphics

 

Brushing

 

Reading Data from a Web Page

 

Computing Sample Quantiles with R