From 1f1521895b7f4911e7ba1863c1e906d191baf004 Mon Sep 17 00:00:00 2001 From: Greg Ridgeway Date: Tue, 4 Sep 2018 10:11:42 -0400 Subject: [PATCH] Move homework solutions offline --- 05 regular expression homework 1.Rmd | 46 ---------------------------- 1 file changed, 46 deletions(-) delete mode 100644 05 regular expression homework 1.Rmd diff --git a/05 regular expression homework 1.Rmd b/05 regular expression homework 1.Rmd deleted file mode 100644 index 167a57b..0000000 --- a/05 regular expression homework 1.Rmd +++ /dev/null @@ -1,46 +0,0 @@ - -### Homework #5 Answers to Exercises - -The text file "scrabble4letter.txt" contains over 4,000 four-letter Scrabble words. Read the .txt file into R as follows: - -```{r comment="", results='hold'} -words <- scan(file="scrabble4letter.txt",what="") -``` - -Write regular expressions (using grep) to find the following items. - -`r .exNum('All words that start with a "z"')` - -`r .exNum('All words that have "zz" in them')` - -`r .exNum('All words that do not have "a", "e", "i", "o", or "u"')` - -`r .exNum('In which letter position are you most likely to find an "r"')` - -`r .exNum('Words that rhyme with "mitt"')` - - -# Solutions to the exercises -1. `r .exerciseQuestions[1]` -```{r comment=""} -grep("^[z]", words, value=TRUE) -``` -2. `r .exerciseQuestions[2]` -```{r comment=""} -grep("zz", words, value=TRUE) -``` -3. `r .exerciseQuestions[3]` -```{r comment=""} -grep("[^aeiou]{4}", words, value=TRUE) -``` -4. `r .exerciseQuestions[4]` -```{r comment=""} -length(grep("^[r]",words,value=TRUE)) #1st -length(grep("[a-z][r][a-z]{2}",words,value=TRUE)) #2nd -length(grep("[a-z]{2}[r][a-z]",words,value=TRUE)) #3rd -length(grep("[r]$",words,value=TRUE)) #4th -``` -5. `r .exerciseQuestions[5]` -```{r comment="", results='hold'} -a<- grep("itt?$", words, value=TRUE) -setdiff(a, c("suit", "toit", "doit", "gait", "wait", "bait"))