Learning Objectives for Quiz 1

Data Types and Operators in R

Data Types

  1. State the main data types used in R.
  2. Given an object, identify its data type.

Operators

  1. Explain what an operator is in the context of computer programming.
  2. State the arithmetic operators in R: +, -, *, ^, /, %%, %/%.
  3. Write and interpret expressions involving the arithmetic operators in R.
  4. Use the help operator ? to pull up documentation about an operator or function.
  5. State the comparison operators in R: <, >, <=, >=, !=, ==.
  6. Write and interpret expressions involving the comparison operators in R.
  7. State the Boolean operators in R: &, |, !.
  8. Write and interpret expressions involving the Boolean operators in R.
  9. Complete a “truth table” for two Boolean variables using one of the &, |, or ! operators.

Querying and Assigning Data Types

  1. Explain what the typeof, is.*, and as.* functions do when passed a data object.
  2. State what the output would be for a given data object passed to one of the typeof, is.*, and as.* functions.

The Assignment Operator and Variables

  1. Define variables in R using the assignment operator <-.
  2. Explain what ‘magic constants’ are, and why they should be avoided.
  3. Give reasons to use variables over magic constants.

Data Structures

Vectors

  1. Define a vector in the context of R.
  2. Create a vector object using c.
  3. Create an empty vector using the vector function.

Vector Access

  1. Access a single element of a vector using the bracket operator.
  2. Use the arithmetic negation operator to access all-but a single element of a vector.
  3. Access multiple elements of a vector using the bracket operator and a vector of indices.
  4. Access multiple elements of a vector using a vector of Booleans.

Vectors and Operators

  1. Use the arithmetic and comparison operators with vector objects.
  2. Explain what vector recycling is.

Naming Vector Elements

  1. Use names to name the elements of a vector.
  2. Access the elements of a vector with named elements.

Arrays

  1. Explain how an array generalizes a vector.
  2. Construct a given 2D array using the array function.
  3. Explain (roughly) how a computer stores data structures in memory.
  4. Compare and contrast column-major and row-major order for storing 2D arrays.
  5. State which of column-major or row-major order R uses by default.
  6. Use the [ ] operator to access a single element of a 2D array both (a) using a pair of integer indices and (b) using a single integer index.
  7. Use the [ ] operator to access rows or columns of a 2D array.

Matrices

  1. Construct a given matrix using the matrix function.

Lists

  1. Explain how a list generalizes a vector.
  2. Compare and constrast how the [ ] and [[ ]] operators access a list.
  3. Access the elements of a list using both [ ] and [[ ]].
  4. Use the function c to extend a vector or list.
  5. Use the length function to query the length of a vector or list.
  6. Use the length function to shorten a vector or list.
  7. Use the names function to name the elements of a list.
  8. Access the elements of a named list using both [ ] and [[ ]].
  9. Access the elements of a named list using the $ operator.
  10. Generate a named list using the list function.