PA 5.1: Scrambled Message

Author

The names of your group members go here!

library(tidyverse)

Read in the Secret Message

message_data <- read_csv("https://github.com/earobinson95/stat331-calpoly/raw/master/practice-activities/data/scrambled_message.txt")

Extracting the Secret Message

For this activity, we will practice using the stringr functions on a character vector. In the code below, we extract the Word column from the message_data, which is then stored as a character vector. With the character vector, you can use indexing (e.g., message[1]) to extract elements.

message <- message_data |> 
  pull(Word)

class(message)
[1] "character"

In this activity, a “word” is a set of characters with no white space. That is, even though many of elements of the scrambled mess vector are nonsense, and some have punctuation, you can consider each element to be a “word”.

Warm-up exercises

  1. How many characters are in the scrambled message?
  1. How many words are in the scrambled message?
  1. Print out every word in the scrambled message that starts with the letter “m”.
  1. Print out every word in the scrambled message that ends with the letter “z”
  1. Print out the punctuation symbols that are present in the scrambled message.
  1. Print out the longest word in the scrambled message.

Decode the Message

Complete the following steps to decode the message.

  1. Remove any spaces before or after each word.
  1. No word should be longer than 16 characters. Drop all extra characters off the end of each word.
  1. Any time you see the word “ugh”, with any number of h’s, followed by a punctuation mark, delete this.
  1. Replace all instances of exactly 2 a’s with exactly 2 e’s.
  1. Replace all z’s with t’s.
  1. Every word that ends in b, change that to a y.
  1. Every word that starts with k (or K), change that to a v (or V).
  1. Recombine all your words into a message.
  1. Find the movie this quote is from.

Canvas Quiz Submission

What is the name of the movie the quote is from?