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

Translation: R-gapminder Section 13 #53

Closed
rikutakei opened this issue Aug 20, 2019 · 0 comments · Fixed by #91
Closed

Translation: R-gapminder Section 13 #53

rikutakei opened this issue Aug 20, 2019 · 0 comments · Fixed by #91
Assignees

Comments

@rikutakei
Copy link
Collaborator

rikutakei commented Aug 20, 2019

Translation of section 13 on dplyr (lines 16940 to 18112)

  • Please assign yourself to the issue before you start translating, so other people knows that you are translating
  • Once you have translated, send a pull request and reference this issue

セクション13 dplyr の翻訳 (16940 から 18112 まで)

  • あなたが翻訳し始めたと分かるように、翻訳を始める前にこのイシューを自分に割り振って(assign)して下さい。
  • 翻訳が終わったら、プルリクエストを開いて、このイシューを参照・リンクして下さい。

i18n/po/r-novice-gapminder.ja.po

Lines 16940 to 18112 in 5f1d2d1

#: r-novice-gapminder/_episodes/13-dplyr.md:1
msgid ""
"---\n"
"# Please do not edit this file directly; it is auto generated.\n"
"# Instead, please edit 13-dplyr.md in _episodes_rmd/\n"
"title: Dataframe Manipulation with dplyr\n"
"teaching: 40\n"
"exercises: 15\n"
"questions:\n"
"- \"How can I manipulate dataframes without repeating myself?\"\n"
"objectives:\n"
"- \" To be able to use the six main dataframe manipulation 'verbs' with pipes in `dplyr`.\"\n"
"- \" To understand how `group_by()` and `summarize()` can be combined to summarize datasets.\"\n"
"- \" Be able to analyze a subset of data using logical filtering.\"\n"
"keypoints:\n"
"- \"Use the `dplyr` package to manipulate dataframes.\"\n"
"- \"Use `select()` to choose variables from a dataframe.\"\n"
"- \"Use `filter()` to choose data based on values.\"\n"
"- \"Use `group_by()` and `summarize()` to work with subsets of data.\"\n"
"- \"Use `mutate()` to create new variables.\"\n"
"source: Rmd\n"
"---"
msgstr ""
"---\n"
"# Please do not edit this file directly; it is auto generated.\n"
"# Instead, please edit 13-dplyr.md in _episodes_rmd/\n"
"title: Dataframe Manipulation with dplyr\n"
"teaching: 40\n"
"exercises: 15\n"
"questions:\n"
"- \"How can I manipulate dataframes without repeating myself?\"\n"
"objectives:\n"
"- \" To be able to use the six main dataframe manipulation 'verbs' with pipes in `dplyr`.\"\n"
"- \" To understand how `group_by()` and `summarize()` can be combined to summarize datasets.\"\n"
"- \" Be able to analyze a subset of data using logical filtering.\"\n"
"keypoints:\n"
"- \"Use the `dplyr` package to manipulate dataframes.\"\n"
"- \"Use `select()` to choose variables from a dataframe.\"\n"
"- \"Use `filter()` to choose data based on values.\"\n"
"- \"Use `group_by()` and `summarize()` to work with subsets of data.\"\n"
"- \"Use `mutate()` to create new variables.\"\n"
"source: Rmd\n"
"---"
#: r-novice-gapminder/_episodes/13-dplyr.md:24
msgid ""
"Manipulation of dataframes means many things to many researchers, we often\n"
"select certain observations (rows) or variables (columns), we often group the\n"
"data by a certain variable(s), or we even calculate summary statistics. We can\n"
"do these operations using the normal base R operations:"
msgstr ""
"Manipulation of dataframes means many things to many researchers, we often\n"
"select certain observations (rows) or variables (columns), we often group the\n"
"data by a certain variable(s), or we even calculate summary statistics. We can\n"
"do these operations using the normal base R operations:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:30
msgid ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Africa\", \"gdpPercap\"])\n"
"~~~"
msgstr ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Africa\", \"gdpPercap\"])\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:37
msgid ""
"~~~\n"
"[1] 2193.755\n"
"~~~"
msgstr ""
"~~~\n"
"[1] 2193.755\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:44
msgid ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Americas\", \"gdpPercap\"])\n"
"~~~"
msgstr ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Americas\", \"gdpPercap\"])\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:51
msgid ""
"~~~\n"
"[1] 7136.11\n"
"~~~"
msgstr ""
"~~~\n"
"[1] 7136.11\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:58
msgid ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Asia\", \"gdpPercap\"])\n"
"~~~"
msgstr ""
"~~~\n"
"mean(gapminder[gapminder$continent == \"Asia\", \"gdpPercap\"])\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:65
msgid ""
"~~~\n"
"[1] 7902.15\n"
"~~~"
msgstr ""
"~~~\n"
"[1] 7902.15\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:70
msgid ""
"But this isn't very *nice* because there is a fair bit of repetition. Repeating\n"
"yourself will cost you time, both now and later, and potentially introduce some\n"
"nasty bugs."
msgstr ""
"But this isn't very *nice* because there is a fair bit of repetition. Repeating\n"
"yourself will cost you time, both now and later, and potentially introduce some\n"
"nasty bugs."
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:74
msgid "## The `dplyr` package"
msgstr "## The `dplyr` package"
#: r-novice-gapminder/_episodes/13-dplyr.md:76
msgid ""
"Luckily, the [`dplyr`](https://cran.r-project.org/web/packages/dplyr/dplyr.pdf)\n"
"package provides a number of very useful functions for manipulating dataframes\n"
"in a way that will reduce the above repetition, reduce the probability of making\n"
"errors, and probably even save you some typing. As an added bonus, you might\n"
"even find the `dplyr` grammar easier to read."
msgstr ""
"Luckily, the [`dplyr`](https://cran.r-project.org/web/packages/dplyr/dplyr.pdf)\n"
"package provides a number of very useful functions for manipulating dataframes\n"
"in a way that will reduce the above repetition, reduce the probability of making\n"
"errors, and probably even save you some typing. As an added bonus, you might\n"
"even find the `dplyr` grammar easier to read."
#: r-novice-gapminder/_episodes/13-dplyr.md:82
msgid ""
"Here we're going to cover 6 of the most commonly used functions as well as using\n"
"pipes (`%>%`) to combine them."
msgstr ""
"Here we're going to cover 6 of the most commonly used functions as well as using\n"
"pipes (`%>%`) to combine them."
# ordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:85
msgid "1. `select()`"
msgstr "1. `select()`"
# ordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:86
msgid "2. `filter()`"
msgstr "2. `filter()`"
# ordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:87
msgid "3. `group_by()`"
msgstr "3. `group_by()`"
# ordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:88
msgid "4. `summarize()`"
msgstr "4. `summarize()`"
# ordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:89
msgid "5. `mutate()`"
msgstr "5. `mutate()`"
#: r-novice-gapminder/_episodes/13-dplyr.md:91
msgid "If you have have not installed this package earlier, please do so:"
msgstr "If you have have not installed this package earlier, please do so:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:94
msgid ""
"~~~\n"
"install.packages('dplyr')\n"
"~~~"
msgstr ""
"~~~\n"
"install.packages('dplyr')\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:99
msgid "Now let's load the package:"
msgstr "Now let's load the package:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:102
msgid ""
"~~~\n"
"library(\"dplyr\")\n"
"~~~"
msgstr ""
"~~~\n"
"library(\"dplyr\")\n"
"~~~"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:107
msgid "## Using select()"
msgstr "## Using select()"
#: r-novice-gapminder/_episodes/13-dplyr.md:109
msgid ""
"If, for example, we wanted to move forward with only a few of the variables in\n"
"our dataframe we could use the `select()` function. This will keep only the\n"
"variables you select."
msgstr ""
"If, for example, we wanted to move forward with only a few of the variables in\n"
"our dataframe we could use the `select()` function. This will keep only the\n"
"variables you select."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:114
msgid ""
"~~~\n"
"year_country_gdp <- select(gapminder,year,country,gdpPercap)\n"
"~~~"
msgstr ""
"~~~\n"
"year_country_gdp <- select(gapminder,year,country,gdpPercap)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:119
msgid "![](../fig/13-dplyr-fig1.png)"
msgstr "![](../fig/13-dplyr-fig1.png)"
#: r-novice-gapminder/_episodes/13-dplyr.md:121
msgid ""
"If we open up `year_country_gdp` we'll see that it only contains the year,\n"
"country and gdpPercap. Above we used 'normal' grammar, but the strengths of\n"
"`dplyr` lie in combining several functions using pipes. Since the pipes grammar\n"
"is unlike anything we've seen in R before, let's repeat what we've done above\n"
"using pipes."
msgstr ""
"If we open up `year_country_gdp` we'll see that it only contains the year,\n"
"country and gdpPercap. Above we used 'normal' grammar, but the strengths of\n"
"`dplyr` lie in combining several functions using pipes. Since the pipes grammar\n"
"is unlike anything we've seen in R before, let's repeat what we've done above\n"
"using pipes."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:128
msgid ""
"~~~\n"
"year_country_gdp <- gapminder %>% select(year,country,gdpPercap)\n"
"~~~"
msgstr ""
"~~~\n"
"year_country_gdp <- gapminder %>% select(year,country,gdpPercap)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:133
msgid ""
"To help you understand why we wrote that in that way, let's walk through it step\n"
"by step. First we summon the gapminder dataframe and pass it on, using the pipe\n"
"symbol `%>%`, to the next step, which is the `select()` function. In this case\n"
"we don't specify which data object we use in the `select()` function since in\n"
"gets that from the previous pipe. **Fun Fact**: There is a good chance you have\n"
"encountered pipes before in the shell. In R, a pipe symbol is `%>%` while in the\n"
"shell it is `|` but the concept is the same!"
msgstr ""
"To help you understand why we wrote that in that way, let's walk through it step\n"
"by step. First we summon the gapminder dataframe and pass it on, using the pipe\n"
"symbol `%>%`, to the next step, which is the `select()` function. In this case\n"
"we don't specify which data object we use in the `select()` function since in\n"
"gets that from the previous pipe. **Fun Fact**: There is a good chance you have\n"
"encountered pipes before in the shell. In R, a pipe symbol is `%>%` while in the\n"
"shell it is `|` but the concept is the same!"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:141
msgid "## Using filter()"
msgstr "## Using filter()"
#: r-novice-gapminder/_episodes/13-dplyr.md:143
msgid ""
"If we now wanted to move forward with the above, but only with European\n"
"countries, we can combine `select` and `filter`"
msgstr ""
"If we now wanted to move forward with the above, but only with European\n"
"countries, we can combine `select` and `filter`"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:147
msgid ""
"~~~\n"
"year_country_gdp_euro <- gapminder %>%\n"
" filter(continent==\"Europe\") %>%\n"
" select(year,country,gdpPercap)\n"
"~~~"
msgstr ""
"~~~\n"
"year_country_gdp_euro <- gapminder %>%\n"
" filter(continent==\"Europe\") %>%\n"
" select(year,country,gdpPercap)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:155
msgid ""
">\n"
"> Write a single command (which can span multiple lines and includes pipes) that\n"
"> will produce a dataframe that has the African values for `lifeExp`, `country`\n"
"> and `year`, but not for other Continents. How many rows does your dataframe\n"
"> have and why?\n"
">\n"
"> > ## Solution to Challenge 1\n"
"> >\n"
"> >~~~\n"
"> >year_country_lifeExp_Africa <- gapminder %>%\n"
"> > filter(continent==\"Africa\") %>%\n"
"> > select(year,country,lifeExp)\n"
"> >~~~\n"
"> >{: .language-r}"
msgstr ""
">\n"
"> Write a single command (which can span multiple lines and includes pipes) that\n"
"> will produce a dataframe that has the African values for `lifeExp`, `country`\n"
"> and `year`, but not for other Continents. How many rows does your dataframe\n"
"> have and why?\n"
">\n"
"> > ## Solution to Challenge 1\n"
"> >\n"
"> >~~~\n"
"> >year_country_lifeExp_Africa <- gapminder %>%\n"
"> > filter(continent==\"Africa\") %>%\n"
"> > select(year,country,lifeExp)\n"
"> >~~~\n"
"> >{: .language-r}"
#: r-novice-gapminder/_episodes/13-dplyr.md:172
msgid ""
"As with last time, first we pass the gapminder dataframe to the `filter()`\n"
"function, then we pass the filtered version of the gapminder dataframe to the\n"
"`select()` function. **Note:** The order of operations is very important in this\n"
"case. If we used 'select' first, filter would not be able to find the variable\n"
"continent since we would have removed it in the previous step."
msgstr ""
"As with last time, first we pass the gapminder dataframe to the `filter()`\n"
"function, then we pass the filtered version of the gapminder dataframe to the\n"
"`select()` function. **Note:** The order of operations is very important in this\n"
"case. If we used 'select' first, filter would not be able to find the variable\n"
"continent since we would have removed it in the previous step."
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:178
msgid "## Using group_by() and summarize()"
msgstr "## Using group_by() and summarize()"
#: r-novice-gapminder/_episodes/13-dplyr.md:180
msgid ""
"Now, we were supposed to be reducing the error prone repetitiveness of what can\n"
"be done with base R, but up to now we haven't done that since we would have to\n"
"repeat the above for each continent. Instead of `filter()`, which will only pass\n"
"observations that meet your criteria (in the above: `continent==\"Europe\"`), we\n"
"can use `group_by()`, which will essentially use every unique criteria that you\n"
"could have used in filter."
msgstr ""
"Now, we were supposed to be reducing the error prone repetitiveness of what can\n"
"be done with base R, but up to now we haven't done that since we would have to\n"
"repeat the above for each continent. Instead of `filter()`, which will only pass\n"
"observations that meet your criteria (in the above: `continent==\"Europe\"`), we\n"
"can use `group_by()`, which will essentially use every unique criteria that you\n"
"could have used in filter."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:208
msgid ""
"~~~\n"
"str(gapminder %>% group_by(continent))\n"
"~~~"
msgstr ""
"~~~\n"
"str(gapminder %>% group_by(continent))\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:215
msgid ""
"~~~\n"
"Classes 'grouped_df', 'tbl_df', 'tbl' and 'data.frame':\t1704 obs. of 6 variables:\n"
" $ country : Factor w/ 142 levels \"Afghanistan\",..: 1 1 1 1 1 1 1 1 1 1 ...\n"
" $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...\n"
" $ pop : num 8425333 9240934 10267083 11537966 13079460 ...\n"
" $ continent: Factor w/ 5 levels \"Africa\",\"Americas\",..: 3 3 3 3 3 3 3 3 3 3 ...\n"
" $ lifeExp : num 28.8 30.3 32 34 36.1 ...\n"
" $ gdpPercap: num 779 821 853 836 740 ...\n"
" - attr(*, \"vars\")= chr \"continent\"\n"
" - attr(*, \"drop\")= logi TRUE\n"
" - attr(*, \"indices\")=List of 5\n"
" ..$ : int 24 25 26 27 28 29 30 31 32 33 ...\n"
" ..$ : int 48 49 50 51 52 53 54 55 56 57 ...\n"
" ..$ : int 0 1 2 3 4 5 6 7 8 9 ...\n"
" ..$ : int 12 13 14 15 16 17 18 19 20 21 ...\n"
" ..$ : int 60 61 62 63 64 65 66 67 68 69 ...\n"
" - attr(*, \"group_sizes\")= int 624 300 396 360 24\n"
" - attr(*, \"biggest_group_size\")= int 624\n"
" - attr(*, \"labels\")='data.frame':\t5 obs. of 1 variable:\n"
" ..$ continent: Factor w/ 5 levels \"Africa\",\"Americas\",..: 1 2 3 4 5\n"
" ..- attr(*, \"vars\")= chr \"continent\"\n"
" ..- attr(*, \"drop\")= logi TRUE\n"
"~~~"
msgstr ""
"~~~\n"
"Classes 'grouped_df', 'tbl_df', 'tbl' and 'data.frame':\t1704 obs. of 6 variables:\n"
" $ country : Factor w/ 142 levels \"Afghanistan\",..: 1 1 1 1 1 1 1 1 1 1 ...\n"
" $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...\n"
" $ pop : num 8425333 9240934 10267083 11537966 13079460 ...\n"
" $ continent: Factor w/ 5 levels \"Africa\",\"Americas\",..: 3 3 3 3 3 3 3 3 3 3 ...\n"
" $ lifeExp : num 28.8 30.3 32 34 36.1 ...\n"
" $ gdpPercap: num 779 821 853 836 740 ...\n"
" - attr(*, \"vars\")= chr \"continent\"\n"
" - attr(*, \"drop\")= logi TRUE\n"
" - attr(*, \"indices\")=List of 5\n"
" ..$ : int 24 25 26 27 28 29 30 31 32 33 ...\n"
" ..$ : int 48 49 50 51 52 53 54 55 56 57 ...\n"
" ..$ : int 0 1 2 3 4 5 6 7 8 9 ...\n"
" ..$ : int 12 13 14 15 16 17 18 19 20 21 ...\n"
" ..$ : int 60 61 62 63 64 65 66 67 68 69 ...\n"
" - attr(*, \"group_sizes\")= int 624 300 396 360 24\n"
" - attr(*, \"biggest_group_size\")= int 624\n"
" - attr(*, \"labels\")='data.frame':\t5 obs. of 1 variable:\n"
" ..$ continent: Factor w/ 5 levels \"Africa\",\"Americas\",..: 1 2 3 4 5\n"
" ..- attr(*, \"vars\")= chr \"continent\"\n"
" ..- attr(*, \"drop\")= logi TRUE\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:239
msgid ""
"You will notice that the structure of the dataframe where we used `group_by()`\n"
"(`grouped_df`) is not the same as the original `gapminder` (`data.frame`). A\n"
"`grouped_df` can be thought of as a `list` where each item in the `list`is a\n"
"`data.frame` which contains only the rows that correspond to the a particular\n"
"value `continent` (at least in the example above)."
msgstr ""
"You will notice that the structure of the dataframe where we used `group_by()`\n"
"(`grouped_df`) is not the same as the original `gapminder` (`data.frame`). A\n"
"`grouped_df` can be thought of as a `list` where each item in the `list`is a\n"
"`data.frame` which contains only the rows that correspond to the a particular\n"
"value `continent` (at least in the example above)."
#: r-novice-gapminder/_episodes/13-dplyr.md:245
msgid "![](../fig/13-dplyr-fig2.png)"
msgstr "![](../fig/13-dplyr-fig2.png)"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:247
msgid "## Using summarize()"
msgstr "## Using summarize()"
#: r-novice-gapminder/_episodes/13-dplyr.md:249
msgid ""
"The above was a bit on the uneventful side but `group_by()` is much more\n"
"exciting in conjunction with `summarize()`. This will allow us to create new\n"
"variable(s) by using functions that repeat for each of the continent-specific\n"
"data frames. That is to say, using the `group_by()` function, we split our\n"
"original dataframe into multiple pieces, then we can run functions\n"
"(e.g. `mean()` or `sd()`) within `summarize()`."
msgstr ""
"The above was a bit on the uneventful side but `group_by()` is much more\n"
"exciting in conjunction with `summarize()`. This will allow us to create new\n"
"variable(s) by using functions that repeat for each of the continent-specific\n"
"data frames. That is to say, using the `group_by()` function, we split our\n"
"original dataframe into multiple pieces, then we can run functions\n"
"(e.g. `mean()` or `sd()`) within `summarize()`."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:257
msgid ""
"~~~\n"
"gdp_bycontinents <- gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap))\n"
"~~~"
msgstr ""
"~~~\n"
"gdp_bycontinents <- gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap))\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:264
msgid "![](../fig/13-dplyr-fig3.png)"
msgstr "![](../fig/13-dplyr-fig3.png)"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:267
msgid ""
"~~~\n"
"continent mean_gdpPercap\n"
" <fctr> <dbl>\n"
"1 Africa 2193.755\n"
"2 Americas 7136.110\n"
"3 Asia 7902.150\n"
"4 Europe 14469.476\n"
"5 Oceania 18621.609\n"
"~~~"
msgstr ""
"~~~\n"
"continent mean_gdpPercap\n"
" <fctr> <dbl>\n"
"1 Africa 2193.755\n"
"2 Americas 7136.110\n"
"3 Asia 7902.150\n"
"4 Europe 14469.476\n"
"5 Oceania 18621.609\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:278
msgid ""
"That allowed us to calculate the mean gdpPercap for each continent, but it gets\n"
"even better."
msgstr ""
"That allowed us to calculate the mean gdpPercap for each continent, but it gets\n"
"even better."
#: r-novice-gapminder/_episodes/13-dplyr.md:282
msgid ""
">\n"
">\n"
"> Calculate the average life expectancy per country. Which has the longest average life\n"
"> expectancy and which has the shortest average life expectancy?\n"
">\n"
"> > ## Solution to Challenge 2\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry <- gapminder %>%\n"
"> > group_by(country) %>%\n"
"> > summarize(mean_lifeExp=mean(lifeExp))\n"
"> >lifeExp_bycountry %>%\n"
"> > filter(mean_lifeExp == min(mean_lifeExp) | mean_lifeExp == max(mean_lifeExp))\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 2 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Iceland 76.5\n"
"> >2 Sierra Leone 36.8\n"
"> >~~~\n"
"> >{: .output}\n"
"> Another way to do this is to use the `dplyr` function `arrange()`, which\n"
"> arranges the rows in a data frame according to the order of one or more\n"
"> variables from the data frame. It has similar syntax to other functions from\n"
"> the `dplyr` package. You can use `desc()` inside `arrange()` to sort in\n"
"> descending order.\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry %>%\n"
"> > arrange(mean_lifeExp) %>%\n"
"> > head(1)\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 1 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Sierra Leone 36.8\n"
"> >~~~\n"
"> >{: .output}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry %>%\n"
"> > arrange(desc(mean_lifeExp)) %>%\n"
"> > head(1)\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 1 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Iceland 76.5\n"
"> >~~~\n"
"> >{: .output}"
msgstr ""
">\n"
">\n"
"> Calculate the average life expectancy per country. Which has the longest average life\n"
"> expectancy and which has the shortest average life expectancy?\n"
">\n"
"> > ## Solution to Challenge 2\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry <- gapminder %>%\n"
"> > group_by(country) %>%\n"
"> > summarize(mean_lifeExp=mean(lifeExp))\n"
"> >lifeExp_bycountry %>%\n"
"> > filter(mean_lifeExp == min(mean_lifeExp) | mean_lifeExp == max(mean_lifeExp))\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 2 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Iceland 76.5\n"
"> >2 Sierra Leone 36.8\n"
"> >~~~\n"
"> >{: .output}\n"
"> Another way to do this is to use the `dplyr` function `arrange()`, which\n"
"> arranges the rows in a data frame according to the order of one or more\n"
"> variables from the data frame. It has similar syntax to other functions from\n"
"> the `dplyr` package. You can use `desc()` inside `arrange()` to sort in\n"
"> descending order.\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry %>%\n"
"> > arrange(mean_lifeExp) %>%\n"
"> > head(1)\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 1 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Sierra Leone 36.8\n"
"> >~~~\n"
"> >{: .output}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_bycountry %>%\n"
"> > arrange(desc(mean_lifeExp)) %>%\n"
"> > head(1)\n"
"> >~~~\n"
"> >{: .language-r}\n"
"> >\n"
"> >\n"
"> >\n"
"> >~~~\n"
"> ># A tibble: 1 x 2\n"
"> > country mean_lifeExp\n"
"> > <fct> <dbl>\n"
"> >1 Iceland 76.5\n"
"> >~~~\n"
"> >{: .output}"
#: r-novice-gapminder/_episodes/13-dplyr.md:352
msgid "The function `group_by()` allows us to group by multiple variables. Let's group by `year` and `continent`."
msgstr "The function `group_by()` allows us to group by multiple variables. Let's group by `year` and `continent`."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:356
msgid ""
"~~~\n"
"gdp_bycontinents_byyear <- gapminder %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap))\n"
"~~~"
msgstr ""
"~~~\n"
"gdp_bycontinents_byyear <- gapminder %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap))\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:363
msgid "That is already quite powerful, but it gets even better! You're not limited to defining 1 new variable in `summarize()`."
msgstr "That is already quite powerful, but it gets even better! You're not limited to defining 1 new variable in `summarize()`."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:366
msgid ""
"~~~\n"
"gdp_pop_bycontinents_byyear <- gapminder %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap),\n"
" sd_gdpPercap=sd(gdpPercap),\n"
" mean_pop=mean(pop),\n"
" sd_pop=sd(pop))\n"
"~~~"
msgstr ""
"~~~\n"
"gdp_pop_bycontinents_byyear <- gapminder %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap),\n"
" sd_gdpPercap=sd(gdpPercap),\n"
" mean_pop=mean(pop),\n"
" sd_pop=sd(pop))\n"
"~~~"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:376
msgid "## count() and n()"
msgstr "## count() and n()"
#: r-novice-gapminder/_episodes/13-dplyr.md:378
msgid ""
"A very common operation is to count the number of observations for each\n"
"group. The `dplyr` package comes with two related functions that help with this."
msgstr ""
"A very common operation is to count the number of observations for each\n"
"group. The `dplyr` package comes with two related functions that help with this."
#: r-novice-gapminder/_episodes/13-dplyr.md:381
msgid ""
"For instance, if we wanted to check the number of countries included in the\n"
"dataset for the year 2002, we can use the `count()` function. It takes the name\n"
"of one or more columns that contain the groups we are interested in, and we can\n"
"optionally sort the results in descending order by adding `sort=TRUE`:"
msgstr ""
"For instance, if we wanted to check the number of countries included in the\n"
"dataset for the year 2002, we can use the `count()` function. It takes the name\n"
"of one or more columns that contain the groups we are interested in, and we can\n"
"optionally sort the results in descending order by adding `sort=TRUE`:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:387
msgid ""
"~~~\n"
"gapminder %>%\n"
" filter(year == 2002) %>%\n"
" count(continent, sort = TRUE)\n"
"~~~"
msgstr ""
"~~~\n"
"gapminder %>%\n"
" filter(year == 2002) %>%\n"
" count(continent, sort = TRUE)\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:396
msgid ""
"~~~\n"
"# A tibble: 5 x 2\n"
" continent n\n"
" <fct> <int>\n"
"1 Africa 52\n"
"2 Asia 33\n"
"3 Europe 30\n"
"4 Americas 25\n"
"5 Oceania 2\n"
"~~~"
msgstr ""
"~~~\n"
"# A tibble: 5 x 2\n"
" continent n\n"
" <fct> <int>\n"
"1 Africa 52\n"
"2 Asia 33\n"
"3 Europe 30\n"
"4 Americas 25\n"
"5 Oceania 2\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:408
msgid ""
"If we need to use the number of observations in calculations, the `n()` function\n"
"is useful. For instance, if we wanted to get the standard error of the life\n"
"expectency per continent:"
msgstr ""
"If we need to use the number of observations in calculations, the `n()` function\n"
"is useful. For instance, if we wanted to get the standard error of the life\n"
"expectency per continent:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:413
msgid ""
"~~~\n"
"gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(se_le = sd(lifeExp)/sqrt(n()))\n"
"~~~"
msgstr ""
"~~~\n"
"gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(se_le = sd(lifeExp)/sqrt(n()))\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:422
msgid ""
"~~~\n"
"# A tibble: 5 x 2\n"
" continent se_le\n"
" <fct> <dbl>\n"
"1 Africa 0.366\n"
"2 Americas 0.540\n"
"3 Asia 0.596\n"
"4 Europe 0.286\n"
"5 Oceania 0.775\n"
"~~~"
msgstr ""
"~~~\n"
"# A tibble: 5 x 2\n"
" continent se_le\n"
" <fct> <dbl>\n"
"1 Africa 0.366\n"
"2 Americas 0.540\n"
"3 Asia 0.596\n"
"4 Europe 0.286\n"
"5 Oceania 0.775\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:434
msgid "You can also chain together several summary operations; in this case calculating the `minimum`, `maximum`, `mean` and `se` of each continent's per-country life-expectancy:"
msgstr "You can also chain together several summary operations; in this case calculating the `minimum`, `maximum`, `mean` and `se` of each continent's per-country life-expectancy:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:437
msgid ""
"~~~\n"
"gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(\n"
" mean_le = mean(lifeExp),\n"
" min_le = min(lifeExp),\n"
" max_le = max(lifeExp),\n"
" se_le = sd(lifeExp)/sqrt(n()))\n"
"~~~"
msgstr ""
"~~~\n"
"gapminder %>%\n"
" group_by(continent) %>%\n"
" summarize(\n"
" mean_le = mean(lifeExp),\n"
" min_le = min(lifeExp),\n"
" max_le = max(lifeExp),\n"
" se_le = sd(lifeExp)/sqrt(n()))\n"
"~~~"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:450
msgid ""
"~~~\n"
"# A tibble: 5 x 5\n"
" continent mean_le min_le max_le se_le\n"
" <fct> <dbl> <dbl> <dbl> <dbl>\n"
"1 Africa 48.9 23.6 76.4 0.366\n"
"2 Americas 64.7 37.6 80.7 0.540\n"
"3 Asia 60.1 28.8 82.6 0.596\n"
"4 Europe 71.9 43.6 81.8 0.286\n"
"5 Oceania 74.3 69.1 81.2 0.775\n"
"~~~"
msgstr ""
"~~~\n"
"# A tibble: 5 x 5\n"
" continent mean_le min_le max_le se_le\n"
" <fct> <dbl> <dbl> <dbl> <dbl>\n"
"1 Africa 48.9 23.6 76.4 0.366\n"
"2 Americas 64.7 37.6 80.7 0.540\n"
"3 Asia 60.1 28.8 82.6 0.596\n"
"4 Europe 71.9 43.6 81.8 0.286\n"
"5 Oceania 74.3 69.1 81.2 0.775\n"
"~~~"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:462
msgid "## Using mutate()"
msgstr "## Using mutate()"
#: r-novice-gapminder/_episodes/13-dplyr.md:464
msgid "We can also create new variables prior to (or even after) summarizing information using `mutate()`."
msgstr "We can also create new variables prior to (or even after) summarizing information using `mutate()`."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:467
msgid ""
"~~~\n"
"gdp_pop_bycontinents_byyear <- gapminder %>%\n"
" mutate(gdp_billion=gdpPercap*pop/10^9) %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap),\n"
" sd_gdpPercap=sd(gdpPercap),\n"
" mean_pop=mean(pop),\n"
" sd_pop=sd(pop),\n"
" mean_gdp_billion=mean(gdp_billion),\n"
" sd_gdp_billion=sd(gdp_billion))\n"
"~~~"
msgstr ""
"~~~\n"
"gdp_pop_bycontinents_byyear <- gapminder %>%\n"
" mutate(gdp_billion=gdpPercap*pop/10^9) %>%\n"
" group_by(continent,year) %>%\n"
" summarize(mean_gdpPercap=mean(gdpPercap),\n"
" sd_gdpPercap=sd(gdpPercap),\n"
" mean_pop=mean(pop),\n"
" sd_pop=sd(pop),\n"
" mean_gdp_billion=mean(gdp_billion),\n"
" sd_gdp_billion=sd(gdp_billion))\n"
"~~~"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:480
msgid "## Connect mutate with logical filtering: ifelse"
msgstr "## Connect mutate with logical filtering: ifelse"
#: r-novice-gapminder/_episodes/13-dplyr.md:482
msgid ""
"When creating new variables, we can hook this with a logical condition. A simple combination of\n"
"`mutate()` and `ifelse()` facilitates filtering right where it is needed: in the moment of creating something new.\n"
"This easy-to-read statement is a fast and powerful way of discarding certain data (even though the overall dimension\n"
"of the data frame will not change) or for updating values depending on this given condition."
msgstr ""
"When creating new variables, we can hook this with a logical condition. A simple combination of\n"
"`mutate()` and `ifelse()` facilitates filtering right where it is needed: in the moment of creating something new.\n"
"This easy-to-read statement is a fast and powerful way of discarding certain data (even though the overall dimension\n"
"of the data frame will not change) or for updating values depending on this given condition."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:488
msgid ""
"~~~\n"
"## keeping all data but \"filtering\" after a certain condition\n"
"# calculate GDP only for people with a life expectation above 25\n"
"gdp_pop_bycontinents_byyear_above25 <- gapminder %>%\n"
" mutate(gdp_billion = ifelse(lifeExp > 25, gdpPercap * pop / 10^9, NA)) %>%\n"
" group_by(continent, year) %>%\n"
" summarize(mean_gdpPercap = mean(gdpPercap),\n"
" sd_gdpPercap = sd(gdpPercap),\n"
" mean_pop = mean(pop),\n"
" sd_pop = sd(pop),\n"
" mean_gdp_billion = mean(gdp_billion),\n"
" sd_gdp_billion = sd(gdp_billion))\n"
"\n"
"## updating only if certain condition is fullfilled\n"
"# for life expectations above 40 years, the gpd to be expected in the future is scaled\n"
"gdp_future_bycontinents_byyear_high_lifeExp <- gapminder %>%\n"
" mutate(gdp_futureExpectation = ifelse(lifeExp > 40, gdpPercap * 1.5, gdpPercap)) %>%\n"
" group_by(continent, year) %>%\n"
" summarize(mean_gdpPercap = mean(gdpPercap),\n"
" mean_gdpPercap_expected = mean(gdp_futureExpectation))\n"
"~~~"
msgstr ""
"~~~\n"
"## keeping all data but \"filtering\" after a certain condition\n"
"# calculate GDP only for people with a life expectation above 25\n"
"gdp_pop_bycontinents_byyear_above25 <- gapminder %>%\n"
" mutate(gdp_billion = ifelse(lifeExp > 25, gdpPercap * pop / 10^9, NA)) %>%\n"
" group_by(continent, year) %>%\n"
" summarize(mean_gdpPercap = mean(gdpPercap),\n"
" sd_gdpPercap = sd(gdpPercap),\n"
" mean_pop = mean(pop),\n"
" sd_pop = sd(pop),\n"
" mean_gdp_billion = mean(gdp_billion),\n"
" sd_gdp_billion = sd(gdp_billion))\n"
"\n"
"## updating only if certain condition is fullfilled\n"
"# for life expectations above 40 years, the gpd to be expected in the future is scaled\n"
"gdp_future_bycontinents_byyear_high_lifeExp <- gapminder %>%\n"
" mutate(gdp_futureExpectation = ifelse(lifeExp > 40, gdpPercap * 1.5, gdpPercap)) %>%\n"
" group_by(continent, year) %>%\n"
" summarize(mean_gdpPercap = mean(gdpPercap),\n"
" mean_gdpPercap_expected = mean(gdp_futureExpectation))\n"
"~~~"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:511
msgid "## Combining `dplyr` and `ggplot2`"
msgstr "## Combining `dplyr` and `ggplot2`"
#: r-novice-gapminder/_episodes/13-dplyr.md:513
msgid ""
"In the plotting lesson we looked at how to make a multi-panel figure by adding\n"
"a layer of facet panels using `ggplot2`. Here is the code we used (with some\n"
"extra comments):"
msgstr ""
"In the plotting lesson we looked at how to make a multi-panel figure by adding\n"
"a layer of facet panels using `ggplot2`. Here is the code we used (with some\n"
"extra comments):"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:518
msgid ""
"~~~\n"
"# Get the start letter of each country\n"
"starts.with <- substr(gapminder$country, start = 1, stop = 1)\n"
"# Filter countries that start with \"A\" or \"Z\"\n"
"az.countries <- gapminder[starts.with %in% c(\"A\", \"Z\"), ]\n"
"# Make the plot\n"
"ggplot(data = az.countries, aes(x = year, y = lifeExp, color = continent)) +\n"
" geom_line() + facet_wrap( ~ country)\n"
"~~~"
msgstr ""
"~~~\n"
"# Get the start letter of each country\n"
"starts.with <- substr(gapminder$country, start = 1, stop = 1)\n"
"# Filter countries that start with \"A\" or \"Z\"\n"
"az.countries <- gapminder[starts.with %in% c(\"A\", \"Z\"), ]\n"
"# Make the plot\n"
"ggplot(data = az.countries, aes(x = year, y = lifeExp, color = continent)) +\n"
" geom_line() + facet_wrap( ~ country)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:529
msgid "<img src=\"../fig/rmd-13-unnamed-chunk-21-1.png\" title=\"plot of chunk unnamed-chunk-21\" alt=\"plot of chunk unnamed-chunk-21\" style=\"display: block; margin: auto;\" />"
msgstr "<img src=\"../fig/rmd-13-unnamed-chunk-21-1.png\" title=\"plot of chunk unnamed-chunk-21\" alt=\"plot of chunk unnamed-chunk-21\" style=\"display: block; margin: auto;\" />"
#: r-novice-gapminder/_episodes/13-dplyr.md:531
msgid ""
"This code makes the right plot but it also creates some variables (`starts.with`\n"
"and `az.countries`) that we might not have any other uses for. Just as we used\n"
"`%>%` to pipe data along a chain of `dplyr` functions we can use it to pass data\n"
"to `ggplot()`. Because `%>%` replaces the first argument in a function we don't\n"
"need to specify the `data =` argument in the `ggplot()` function. By combining\n"
"`dplyr` and `ggplot2` functions we can make the same figure without creating any\n"
"new variables or modifying the data."
msgstr ""
"This code makes the right plot but it also creates some variables (`starts.with`\n"
"and `az.countries`) that we might not have any other uses for. Just as we used\n"
"`%>%` to pipe data along a chain of `dplyr` functions we can use it to pass data\n"
"to `ggplot()`. Because `%>%` replaces the first argument in a function we don't\n"
"need to specify the `data =` argument in the `ggplot()` function. By combining\n"
"`dplyr` and `ggplot2` functions we can make the same figure without creating any\n"
"new variables or modifying the data."
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:540
msgid ""
"~~~\n"
"gapminder %>%\n"
" # Get the start letter of each country\n"
" mutate(startsWith = substr(country, start = 1, stop = 1)) %>%\n"
" # Filter countries that start with \"A\" or \"Z\"\n"
" filter(startsWith %in% c(\"A\", \"Z\")) %>%\n"
" # Make the plot\n"
" ggplot(aes(x = year, y = lifeExp, color = continent)) +\n"
" geom_line() +\n"
" facet_wrap( ~ country)\n"
"~~~"
msgstr ""
"~~~\n"
"gapminder %>%\n"
" # Get the start letter of each country\n"
" mutate(startsWith = substr(country, start = 1, stop = 1)) %>%\n"
" # Filter countries that start with \"A\" or \"Z\"\n"
" filter(startsWith %in% c(\"A\", \"Z\")) %>%\n"
" # Make the plot\n"
" ggplot(aes(x = year, y = lifeExp, color = continent)) +\n"
" geom_line() +\n"
" facet_wrap( ~ country)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:553
msgid "<img src=\"../fig/rmd-13-unnamed-chunk-22-1.png\" title=\"plot of chunk unnamed-chunk-22\" alt=\"plot of chunk unnamed-chunk-22\" style=\"display: block; margin: auto;\" />"
msgstr "<img src=\"../fig/rmd-13-unnamed-chunk-22-1.png\" title=\"plot of chunk unnamed-chunk-22\" alt=\"plot of chunk unnamed-chunk-22\" style=\"display: block; margin: auto;\" />"
#: r-novice-gapminder/_episodes/13-dplyr.md:555
msgid ""
"Using `dplyr` functions also helps us simplify things, for example we could\n"
"combine the first two steps:"
msgstr ""
"Using `dplyr` functions also helps us simplify things, for example we could\n"
"combine the first two steps:"
# code block
#: r-novice-gapminder/_episodes/13-dplyr.md:559
msgid ""
"~~~\n"
"gapminder %>%\n"
" # Filter countries that start with \"A\" or \"Z\"\n"
"\tfilter(substr(country, start = 1, stop = 1) %in% c(\"A\", \"Z\")) %>%\n"
"\t# Make the plot\n"
"\tggplot(aes(x = year, y = lifeExp, color = continent)) +\n"
"\tgeom_line() +\n"
"\tfacet_wrap( ~ country)\n"
"~~~"
msgstr ""
"~~~\n"
"gapminder %>%\n"
" # Filter countries that start with \"A\" or \"Z\"\n"
"\tfilter(substr(country, start = 1, stop = 1) %in% c(\"A\", \"Z\")) %>%\n"
"\t# Make the plot\n"
"\tggplot(aes(x = year, y = lifeExp, color = continent)) +\n"
"\tgeom_line() +\n"
"\tfacet_wrap( ~ country)\n"
"~~~"
#: r-novice-gapminder/_episodes/13-dplyr.md:570
msgid "<img src=\"../fig/rmd-13-unnamed-chunk-23-1.png\" title=\"plot of chunk unnamed-chunk-23\" alt=\"plot of chunk unnamed-chunk-23\" style=\"display: block; margin: auto;\" />"
msgstr "<img src=\"../fig/rmd-13-unnamed-chunk-23-1.png\" title=\"plot of chunk unnamed-chunk-23\" alt=\"plot of chunk unnamed-chunk-23\" style=\"display: block; margin: auto;\" />"
#: r-novice-gapminder/_episodes/13-dplyr.md:573
msgid ""
">\n"
"> Calculate the average life expectancy in 2002 of 2 randomly selected countries\n"
"> for each continent. Then arrange the continent names in reverse order.\n"
"> **Hint:** Use the `dplyr` functions `arrange()` and `sample_n()`, they have\n"
"> similar syntax to other dplyr functions.\n"
">\n"
"> > ## Solution to Advanced Challenge\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_2countries_bycontinents <- gapminder %>%\n"
"> > filter(year==2002) %>%\n"
"> > group_by(continent) %>%\n"
"> > sample_n(2) %>%\n"
"> > summarize(mean_lifeExp=mean(lifeExp)) %>%\n"
"> > arrange(desc(mean_lifeExp))\n"
"> >~~~\n"
"> >{: .language-r}"
msgstr ""
">\n"
"> Calculate the average life expectancy in 2002 of 2 randomly selected countries\n"
"> for each continent. Then arrange the continent names in reverse order.\n"
"> **Hint:** Use the `dplyr` functions `arrange()` and `sample_n()`, they have\n"
"> similar syntax to other dplyr functions.\n"
">\n"
"> > ## Solution to Advanced Challenge\n"
"> >\n"
"> >~~~\n"
"> >lifeExp_2countries_bycontinents <- gapminder %>%\n"
"> > filter(year==2002) %>%\n"
"> > group_by(continent) %>%\n"
"> > sample_n(2) %>%\n"
"> > summarize(mean_lifeExp=mean(lifeExp)) %>%\n"
"> > arrange(desc(mean_lifeExp))\n"
"> >~~~\n"
"> >{: .language-r}"
# header
#: r-novice-gapminder/_episodes/13-dplyr.md:593
#: r-novice-gapminder/_episodes/14-tidyr.md:645
msgid "## Other great resources"
msgstr "## Other great resources"
# unordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:595
msgid "* [R for Data Science](http://r4ds.had.co.nz/)"
msgstr "* [R for Data Science](http://r4ds.had.co.nz/)"
# unordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:596
#: r-novice-gapminder/_episodes/14-tidyr.md:648
msgid "* [Data Wrangling Cheat sheet](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf)"
msgstr "* [Data Wrangling Cheat sheet](https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf)"
# unordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:597
msgid "* [Introduction to dplyr](https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html)"
msgstr "* [Introduction to dplyr](https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html)"
# unordered list
#: r-novice-gapminder/_episodes/13-dplyr.md:598
#: r-novice-gapminder/_episodes/14-tidyr.md:650
msgid "* [Data wrangling with R and RStudio](https://www.rstudio.com/resources/webinars/data-wrangling-with-r-and-rstudio/)"
msgstr "* [Data wrangling with R and RStudio](https://www.rstudio.com/resources/webinars/data-wrangling-with-r-and-rstudio/)"

@joelnitta joelnitta changed the title Translation: Lesson13 Translation: R-gapminder Section 13 Dec 6, 2019
@rkkmk rkkmk self-assigned this Mar 21, 2020
@rkkmk rkkmk linked a pull request Apr 19, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants