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")

Working with the Secret Message Data

If you preview the data, you’ll notice this is a very simple data frame with only one column—Word. This column contains strings (or words).

In this activity, when I say “word” I mean 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”.

message_data
# A tibble: 127 × 1
   Word                     
   <chr>                    
 1 Koila!                   
 2 In                       
 3 kiew,                    
 4 a                        
 5 humble                   
 6 kaudevillianugh?aoghajdbn
 7 kezeran,                 
 8 casz                     
 9 kicariouslb              
10 as                       
# ℹ 117 more rows

Since the Word is stored in a data frame, you will need to use some of the dplyr functions you have learned to work with the data.

For example, if you need to find words that have a certain pattern, then you will likely want to pair a str_XXXX() function with filter().

If you need to make changes to the words, then you will likely want to pair a str_XXXX() function with mutate().

If you want to summarize patterns in the words, then you will likely want to pair a str_XXXX() function with summarize().

Warm-up Exercises

  1. Print out every word in the scrambled message that starts with the letter “m”. Hint: What symbol do you use to indicate the beginning of a string?
  1. Print out every word in the scrambled message that ends with the letter “z”. Hint: What symbol do you use to indicate the end of a string?
  1. Print out the punctuation symbols that are present in the scrambled message. Hint: You don’t need to type out every punctuation symbol! There is a shortcut way to look for any punctuation symbol.
  1. Print out the words that have more than 12 characters. Hint: This should take two steps!
  1. Print out the longest word in the scrambled message. Hint: If you already have the length of each word, you can grab the max easily!

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?