Skip to content

Commit

Permalink
Fix markdown formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jrnold committed Jul 31, 2018
1 parent 9dfeecc commit 00515f8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .remarkrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
["remark-lint-no-undefined-references", false],
["remark-lint-emphasis-marker", false],
["remark-lint-fenced-code-flag", false],
["remark-lint-no-duplicate-headings", false]
["remark-lint-no-duplicate-headings", false],
["remark-lint-maximum-heading-length", false]
]
}
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- Update code for Ex 5.7.7 to be cleaner (#41)
- Fix various typos (dongzhuoer #39, #40, #43, #45, #46, #47, #48)


## 2018-07-28

- Fix miscellaneous typos (dongzhuoer, #31, #33, #34, #35, #36, #37)
Expand Down
12 changes: 6 additions & 6 deletions relational-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Identify the keys in the following datasets

The answer to each part follows.

1. The primary key for `Lahman::Batting` is `playerID`, `yearID`, `stint`.
1. The primary key for `Lahman::Batting` is `playerID`, `yearID`, `stint`.
It is not simply `playerID`, `yearID` because players can have different stints in different leagues within the same year.

```{r}
Expand All @@ -114,7 +114,7 @@ The answer to each part follows.
nrow()
```

1. The primary key for `babynames::babynames` is `year`, `sex`, `name`.
1. The primary key for `babynames::babynames` is `year`, `sex`, `name`.
It is not simply `year`, `name` since names can appear for both sexes with different counts.

```{r}
Expand All @@ -124,7 +124,7 @@ The answer to each part follows.
nrow()
```

1. The primary key for `nasaweather::atmos` is the location and time of the measurement: `lat`, `long`, `year`, `month`.
1. The primary key for `nasaweather::atmos` is the location and time of the measurement: `lat`, `long`, `year`, `month`.

```{r}
nasaweather::atmos %>%
Expand Down Expand Up @@ -294,11 +294,11 @@ Add the location of the origin and destination (i.e. the `lat` and `lon`) to `fl

`r BeginAnswer()`

You can perform one join after another. If duplicate variables are found, by default, dplyr will distinguish the two by adding `.x`, and `.y` to the ends of the variable names to solve naming conflicts.
You can perform one join after another. If duplicate variables are found, by default, dplyr will distinguish the two by adding `.x`, and `.y` to the ends of the variable names to solve naming conflicts.
```{r}
airport_locations <- airports %>%
select(faa, lat, lon)
flights %>%
select(year:day, hour, origin, dest) %>%
left_join(
Expand All @@ -314,7 +314,7 @@ This default can be over-ridden using the `suffix` argument.
```{r}
airport_locations <- airports %>%
select(faa, lat, lon)
flights %>%
select(year:day, hour, origin, dest) %>%
left_join(
Expand Down
32 changes: 17 additions & 15 deletions strings.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ The answer to each part follows.
```{r eval=is_html}
str_view(stringr::words, "^y", match =TRUE)
```

1. End with “x”

```{r eval=is_html}
str_view(stringr::words, "x$", match = TRUE)
```
Expand All @@ -262,6 +263,7 @@ The answer to each part follows.
```

1. The words that have seven letters or more are

```{r eval=is_html}
str_view(stringr::words, ".......", match = TRUE)
```
Expand Down Expand Up @@ -294,7 +296,7 @@ The answer to each part follows.
```

1. Words that contain only consonants

```{r eval=is_html}
str_view(stringr::words, "^[^aeiou]+$", match=TRUE)
```
Expand All @@ -308,7 +310,7 @@ The answer to each part follows.
```

1. Words ending in `ing` or `ise`:

```{r eval=is_html}
str_view(stringr::words, "i(ng|se)$", match = TRUE)
```
Expand Down Expand Up @@ -592,11 +594,11 @@ The answer to each part follows.
```{r eval=is_html}
str_view(words, "([[:letter:]]).*\\1")
```
Note that these patterns are case sensitive. Use the

Note that these patterns are case sensitive. Use the
case insensitive flag if you want to check for repeated pairs
of letters with different capitalization.
of letters with different capitalization.

The `\\1` is used to refer back to the first group (`(.)`) so that whatever letter is matched by `[A-Za-z]` is again matched.

1. This regex matches words that contain one letter repeated in at least three places.
Expand Down Expand Up @@ -655,7 +657,7 @@ The answer to each part follows.
that contain at least one of each vowel. The regular expression
would need to consider all possible orders in which the vowels
could occur.

```{r}
pattern <-
cross_n(rerun(5, c("a", "e", "i", "o", "u")),
Expand All @@ -668,14 +670,14 @@ The answer to each part follows.
```

To check that this pattern works, test it on a pattern that
should match
should match
```{r}
str_subset("aseiouds", pattern)
```
Using multiple `str_detect()` calls, one pattern for each vowel,

Using multiple `str_detect()` calls, one pattern for each vowel,
produces a much simpler and readable answer.

```{r}
str_subset(words, pattern)
Expand All @@ -685,15 +687,15 @@ The answer to each part follows.
str_detect(words, "o") &
str_detect(words, "u")]
```

There appear to be none.

1. The word with the highest number of vowels is
```{r}
vowels <- str_count(words, "[aeiou]")
words[which(vowels == max(vowels))]
```

The word with the highest proportion of vowels is
```{r}
prop_vowels <- str_count(words, "[aeiou]") / str_length(words)
Expand Down Expand Up @@ -769,7 +771,7 @@ The answer to each part follows.
1. Finding all plurals cannot be correctly accoplished with regular expressions alone.
Finding plural words would at least require morphological information about words in the language.
See [WordNet](https://cran.r-project.org/web/packages/wordnet/index.html) for a resource that would do that.
However, identifying words that end in an "s" and with more than three characters, in order to remove "as", "is", "gas", etc., is
However, identifying words that end in an "s" and with more than three characters, in order to remove "as", "is", "gas", etc., is
a reasonable heuristic.

```{r}
Expand Down
1 change: 0 additions & 1 deletion tibble.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Practice referring to non-syntactic names in the following data frame by:
For this example, I'll create a dataset called annoying with
columns named `1` and `2`.


```{r}
annoying <- tibble(
`1` = 1:10,
Expand Down
14 changes: 8 additions & 6 deletions transform.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,16 @@ Compare `air_time` with `arr_time - dep_time`. What do you expect to see? What d

`r BeginAnswer()`

Since `arr_time` and `dep_time` may be in different time zones, the `air_time` doesn't equal the difference.
We would need to account for time-zones in these calculations.
Since `arr_time` and `dep_time` may be in different time zones, the `air_time` does not equal the differences.

```{r}
mutate(flights,
air_time2 = arr_time - dep_time,
air_time_diff = air_time2 - air_time) %>%
air_times <- mutate(flights,
arr_time_min = arr_time %/% 100 * 60 + arr_time %% 100,
dep_time_min = dep_time %/% 100 * 60 + dep_time %% 100,
air_time_2 = (arr_time_min - dep_time_min + 1440) %% 1440,
air_time_diff = air_time_2 - air_time) %>%
filter(air_time_diff != 0) %>%
select(air_time, air_time2, dep_time, arr_time, dest)
select(air_time, air_time_2, dep_time, arr_time, dest)
```

`r EndAnswer()`
Expand Down

0 comments on commit 00515f8

Please sign in to comment.