Learning Objectives for Quiz 2

Conditional Statements

  1. Write an if statement to select between expressions based on a condition.
  2. Use the correct syntax for an if statement in R.
  3. Given the components of a condition and an if statement, determine the output produced by R.
  4. Write a “compound” condition using the comparison and logical operators.
  5. Use the “twin” logical operators && and || to construct a condition.
  6. Explain what it means that the “twin” logical operators evaluate lazily.
  7. Write if, if-else, and if-else if-else statements.

Iteration

for

  1. Explain how a for loop can simplify code.
  2. Write a for loop to perform an indicated sequence of commands in R.
  3. Use the correct syntax for a for loop in R.
  4. Given a for loop, determine the outputs stored in each variable within the loop after the loop has completed.

while

  1. Explain how a while loop differs from a for loop.
  2. Write a while loop to perform an indicated sequence of commands in R.
  3. Use the correct syntax for a while loop in R.
  4. Given a while loop, determine the outputs stored in each variable within the loop after the loop has terminated.
  5. Describe situations where a while loop or for loop is preferred.
  6. Use show to make the innards of a loop transparent.

Vectorization

  1. Explain what it means for a function to be vectorized.
  2. Describe the benefits of using vectorized functions.

String Manipulation

String Basics

  1. Distinguish between a character and a string.
  2. Access the upper- and lower-case Roman letters using letters and LETTERS.
  3. Recognize and use the whitespace characters "\n" and "\t" for line breaks and tabs.
  4. Use cat to print a string to the console with formatting.
  5. Create, access, and manipulate vectors, arrays, lists, etc., of strings.

Counting Characters in a String

  1. Use nchar to count the number of characters in a string.
  2. Explain why length is inappropriate to count the number of characters in a string.
  3. Use the vectorization capabilities of nchar to count the number of characters in a vector or array of strings.

Substrings

  1. Use substr to access and manipulate substrings in a string.
  2. Interpret commands involving substr, including those that involve vectorization and recycling.
  3. Explain why [ ] cannot be used to access or manipulate the characters in a string.

Splitting a String

  1. Use strsplit to split a string.
  2. Explain why strsplit returns a list of character vectors rather than a single character vector.
  3. Given a string and a desired splitting string, access a given substring returned by strsplit.

Combining Strings

  1. Use paste to join two or more strings with a desired delimiter.
  2. Interpret commands involving paste, including those that involve vectorization and recycling.
  3. Use paste with vectorization to collapse several strings into a single string.

Reading in and Summarizing Text

  1. Use readLines to extract text from an online or offline file.
  2. Describe the data structure returned by readLines.
  3. Perform “reconstitution” to combine a vector of strings into a single string and then split that string based on a delimiter.
  4. Use table and reconstitution to count the number of words in a string.
  5. Explain the structure of table in terms of names and counts.
  6. Use an output from table to query for the number of times a given substring appears in a string.