Learning Objectives for Quiz 1
Data Types and Operators in R
Data Types
- State the main data types used in R.
- Given an object, identify its data type.
Operators
- Explain what an operator is in the context of computer programming.
- State the arithmetic operators in R:
+
, -
, *
, ^
, /
, %%
, %/%
.
- Write and interpret expressions involving the arithmetic operators in R.
- Use the help operator
?
to pull up documentation about an operator or function.
- State the comparison operators in R:
<
, >
, <=
, >=
, !=
, ==
.
- Write and interpret expressions involving the comparison operators in R.
- State the Boolean operators in R:
&
, |
, !
.
- Write and interpret expressions involving the Boolean operators in R.
- Complete a “truth table” for two Boolean variables using one of the
&
, |
, or !
operators.
Querying and Assigning Data Types
- Explain what the
typeof
, is.*
, and as.*
functions do when passed a data object.
- 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
- Define variables in R using the assignment operator
<-
.
- Explain what ‘magic constants’ are, and why they should be avoided.
- Give reasons to use variables over magic constants.
Data Structures
Vectors
- Define a vector in the context of R.
- Create a vector object using
c
.
- Create an empty vector using the
vector
function.
Vector Access
- Access a single element of a vector using the bracket operator.
- Use the arithmetic negation operator to access all-but a single element of a vector.
- Access multiple elements of a vector using the bracket operator and a vector of indices.
- Access multiple elements of a vector using a vector of Booleans.
Vectors and Operators
- Use the arithmetic and comparison operators with vector objects.
- Explain what vector recycling is.
Naming Vector Elements
- Use
names
to name the elements of a vector.
- Access the elements of a vector with named elements.
Arrays
- Explain how an array generalizes a vector.
- Construct a given 2D array using the
array
function.
- Explain (roughly) how a computer stores data structures in memory.
- Compare and contrast column-major and row-major order for storing 2D arrays.
- State which of column-major or row-major order R uses by default.
- 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.
- Use the
[ ]
operator to access rows or columns of a 2D array.
Matrices
- Construct a given matrix using the
matrix
function.
Lists
- Explain how a list generalizes a vector.
- Compare and constrast how the
[ ]
and [[ ]]
operators access a list.
- Access the elements of a list using both
[ ]
and [[ ]]
.
- Use the function
c
to extend a vector or list.
- Use the
length
function to query the length of a vector or list.
- Use the
length
function to shorten a vector or list.
- Use the
names
function to name the elements of a list.
- Access the elements of a named list using both
[ ]
and [[ ]]
.
- Access the elements of a named list using the
$
operator.
- Generate a named list using the
list
function.