Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 93-appendixC.Rmd #486

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 93-appendixC.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Let's load all the packages needed for this chapter (this assumes you've already
* `dplyr` for data wrangling
* `tidyr` for converting data to "tidy" format
* `readr` for importing spreadsheet data into R
* As well as the more advanced `purrr`, `tibble`, `stringr`, and `forcats` packages
* As well as the more advanced `purrr`, `tibble`, `stringr`, and `forcats` packages.

If needed, read Section \@ref(packages) for information on how to install and load R packages.

Expand Down Expand Up @@ -128,7 +128,7 @@ ggplot(revenue_by_type, aes(x = type, y = total_revenue)) +
labs(x = "Movie genre", y = "Total boxoffice revenue (in millions of $)")
```

Or if you want to reorder `type` in ascending order of `total_revenue`, we use `reorder()`
Or if you want to reorder `type` in ascending order of `total_revenue`, we use `reorder()`:

```{r}
revenue_by_type <- revenue_by_type %>%
Expand Down Expand Up @@ -156,7 +156,7 @@ ggplot(revenue_by_type, aes(x = type, y = total_revenue)) +
```

For more advanced categorical variable (i.e. factor) manipulations, check out
the [`forcats` package](https://forcats.tidyverse.org/){target="_blank"}. Note: `forcats` is an anagram of `factors`
the [`forcats` package](https://forcats.tidyverse.org/){target="_blank"}. Note: `forcats` is an anagram of `factors`.


![](https://github.com/tidyverse/forcats/blob/main/man/figures/logo.png?raw=true){width=20%}
Expand Down Expand Up @@ -204,7 +204,7 @@ movies_ex %>%
slice(1:10)
```

Do the same here, but return `"not romantic comedy"` if `type` is not `"rom comedy"` and this time overwrite the original `type` variable
Do the same here, but return `"not romantic comedy"` if `type` is not `"rom comedy"` and this time overwrite the original `type` variable:

```{r}
movies_ex %>%
Expand Down Expand Up @@ -316,7 +316,7 @@ So for example, the 4 proportions corresponding to R rated movies are 0.596 + 0.

### Dealing with %, commas, and \$ {#appendix-commas}

Say you have numerical data that are recorded as percentages, have commas, or are in dollar form and hence are character strings. How do you convert these to numerical values? Using the `parse_number()` function from the `readr` package inside a `mutate()`! Shout out to [Stack Overflow](https://stackoverflow.com/a/52965808/3674500){target="_blank"}
Say you have numerical data that are recorded as percentages, have commas, or are in dollar form and hence are character strings. How do you convert these to numerical values? Using the `parse_number()` function from the `readr` package inside a `mutate()`! Shout out to [Stack Overflow](https://stackoverflow.com/a/52965808/3674500){target="_blank"}.

```{r}
library(readr)
Expand Down
Loading