R Quiz (Quiz #3)

This exam consists of nine multiple choice questions. For each, circle the letter corresponding to the best answer. You are not permitted to look at any papers, books, or other material during this test.
  1. Which of the following statements in R are "legal" (i.e., will not generate an error)
    1. 1 = 2
    2. help("t.test)"
    3. z = x > y
    4. x == x
  2. Consider the following data frame:
      n  s  b
    1 1  6 aa
    2 5  9 aa
    3 7  3 bb
    4 9  7 bb
    5 2 12 cc
    If I execute the following command in R, what will result?
       mysel = df[df$n<=7,]
    1. mysel will contain a copy of df
    2. mysel will contain a copy of the df data frame with all rows where n is less than or equal to 7 dropped
    3. mysel will contain a copy of the df data frame with all rows where n is less than to 7 dropped
    4. mysel will be a vector of numbers less then 7
  3. Referring to the data frame defined above, how to you access the "b" column? Check all that will work
    1. df[[3]]
    2. df[["b"]]
    3. df$b
    4. df[,"b"]
    5. df[df$b,]
  4. Why do you have a separate script file for R?
    1. So you can turn in your assignment at the end of the lab
    2. It is required for R to function
    3. To organize your code and help you reconstruct your analysis steps later
  5. If a line in a script or command begins with a '#' character, what does it mean?
    1. Perform a t-test
    2. Multiplication
    3. The line will be ignored
    4. Select the column indicated by the next command
  6. What is the "working directory" in R?
    1. The directory that the R interpreter is currently "looking at". Filenames are relative to this folder
    2. The place with R's configuration files are stored
    3. The place with files must be saved in order to be used with R
  7. How do you check the contents of a variable in R? (e.g., suppose you wanted to see what is "inside" a variable named 'mydata')
    1. Type 'mydata' on a line by itself into the R interpreter/interactive session
    2. help(mydata)
    3. look(mydata)
    4. head(mydata)
  8. How do you check the current working directory that R is using
    1. dir()
    2. help(dir)
    3. getwd()
    4. workingdir()
  9. Using the data frame defined above, what would happen if you execute the following command:
            tapply(df$n,df$b, mean)
    1. a vector c(3, 8, 2) which is the mean of the values in column n that share the same value on column b
    2. a matrix containing all the data in the frame
    3. a vector like c(1,5,7,9)
    4. the values in column s