This is the Markdown file for the my third homework assignment. The problem statement is as follows:

Before we begin, let’s get this library stringr

## Warning: package 'stringr' was built under R version 3.6.3

Problem 3: Copy the introductory example.

  1. Use the tools…..

Yank given string into program variable raw.data:

Remove some non-alpha characters e.g. numbers, brackets, hyphens:

## [1] "Moe Szyslak"          "Burns, C. Montgomery" "Rev. Timothy Lovejoy"
## [4] "Ned Flanders"         "Simpson, Homer"       "Dr. Julius Hibbert"

Remove “C.”, “Rev. ”, “Dr. ”, and “,”. Piped the processes with “>%”. It’s like the Unix/Linux pipe “|”. It’s not mentioned in the chapter, but I looked up.

## [1] "Moe Szyslak"      "Burns Montgomery" "Timothy Lovejoy"  "Ned Flanders"    
## [5] "Simpson Homer"    "Julius Hibbert"

Split first_name and last_name.

Creating heading.

Print names.df, with proper heading and formatting.

##   first_name last_name 
## 1 Moe        Szyslak   
## 2 Burns      Montgomery
## 3 Timothy    Lovejoy   
## 4 Ned        Flanders  
## 5 Simpson    Homer     
## 6 Julius     Hibbert
  1. Construct a logical vector ….. has a title (i.e., Rev. and Dr.)

Logical vector to find Dr. or Rev.

## [1] FALSE FALSE  TRUE FALSE FALSE  TRUE
  1. Construct a logical vector ….. has a second name.

Logical vector to find middle name C., as in one case. This is done differently from the previous one.

## [1] FALSE  TRUE FALSE FALSE FALSE FALSE

Problem 4: Describe the types of strings…..

  1. [0-9]+\$ : Anywhere in the string, there has to be numeric character, immediately followed by the \(-character, e.g. "CCCC4\)BBB".
## [1]  TRUE FALSE FALSE
  1. \b[a-z]{1,4}\b : Anywhere in the string, there has to be a lowercase word (i.e. a preceded and followed by white space), which is at least one character long but at most 4 characters.
## [1] FALSE  TRUE FALSE
  1. .*?\.txt$ : The string has to end with .txt.
## [1]  TRUE FALSE FALSE
  1. \d{2}/\d{2}/\d{4} : The string must contain nn/nn/nnnn, where n stands for numeric.
## [1]  TRUE  TRUE FALSE
  1. <(.+?)>.+?</\1> : The following example will exemplify better than a wordy description.
## [1]  TRUE FALSE FALSE

Problem 9: Secret message.

First yank the string, containing secret message, into program variable

## [1] "clcopCow1zmstc0d87wnkig7OvdicpNuggvhryn92Gjuwczi8hqrfpRxs5Aj5dwpn0Tanwo\nUwisdij7Lj8kpf03AT5Idr3coc0bt7yczjatOaootj55t3Nj3ne6c4Sfek.r1w1YwwojigO\nd6vrfUrbz2.2bkAnbhzgv4R9i05zEcrop.wAgnb.SqoU65fPa1otfb7wEm24k6t3sR9zqe5\nfy89n6Nd5t9kc4fE905gmc4Rgxo5nhDk!gr"

It’s visible that there are some capitalized characters, and mostly small characters. Let’s try to extract those capitalized characters.

##  [1] "C"  "O"  "N"  "G"  "R"  "A"  "T"  "U"  "L"  "AT" "I"  "O"  "N"  "S"  "." 
## [16] "Y"  "O"  "U"  "."  "A"  "R"  "E"  "."  "A"  ".S" "U"  "P"  "E"  "R"  "N" 
## [31] "E"  "R"  "D"

The above process produces a bunch of capital letters, with occassional dots. We’ll build words out of those capital letters.

Created 5 words. Now, I’ll create a complete sentence or phrase out of the five words.

## [1] "CONGRATULATIONS YOU ARE A SUPERNERD"

Marker: 607-03