Review - Cipher

Stat 251

2025-02-04

Topics to Know

Review: General Programming

Know how to:

  • Define a variable
  • Write a function
  • Write an if/else statement
  • load a package or import a library
  • Create a data table structure
  • Get a column, row, or value from a data table
  • Get an item from a list

Vectors in R

x <- c(11, 25, 18, 4, 1, 5, 17, 22, 3,  9)

str(x)
 num [1:10] 11 25 18 4 1 5 17 22 3 9
length(x)
[1] 10

Quick-Info: how many values are below 10?

sum(x < 10)
[1] 5
which(x < 10)
[1]  4  5  6  9 10

Update values: turn all values of 3 into a 4:

Your Turn

make all square values in x negative:

  1. Write a function is_square that takes a numeric vector x and returns a vector of TRUE/FALSE for each element in x (TRUE: element is square, FALSE: element is not a square number)

  2. update square values by their negative number

x

 [1] 11 25 18  4  1  5 17 22  4  9

is_square(x):

 [1] FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE

updated x:

 [1]  11 -25  18  -4  -1   5  17  22  -4  -9

Homework - Review

  • in Canvas, accept the Github Classroom link to homework #3

  • Clone the repository to your local machine

  • Render the file index.qmd

Homework - Cipher

  • Not all statements that execute are correct (Part 1: fix mistakes)

  • Part 2: write a decoder

  • Part 3: Decode the secret message!

Next Time

  • Continue working on Homework 3

  • Self Assessment quiz due Thursday