Referencing code results in the report
In this exercise, you'll use summarize() and brazil_investment_projects_2018 to find the total investment amount for all projects in Brazil in the 2018 fiscal year. Then, you'll add text to the report to include the information and reference the code results in the text, so that the calculated amount is printed in the text of the report when you knit the file.
Cet exercice fait partie du cours
Reporting with R Markdown
Instructions
- In the brazil-investment-projects-2018code chunk, createbrazil_investment_projects_2018_totalby summarizing the data that was filtered for projects in Brazil in the 2018 fiscal year to create a new column,sum_total_investment, that contains the sum of thetotal_investmentamounts for each of the projects.
- Add Braziland2018to the sentence on line47to describe the information that was calculated.
- Add a reference to brazil_investment_projects_2018_totalin the sentence on line47, so that the total investment amount for all projects in Brazil in the 2018 fiscal year is included in the knit report.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
{"investment_report.Rmd":"---\ntitle: \"Investment Report\"\ndate: \"`r format(Sys.time(), '%d %B %Y')`\"\noutput: html_document\n---\n\n```{r data, include = FALSE}\nlibrary(readr)\nlibrary(dplyr)\n\ninvestment_annual_summary <- read_csv(\"https://assets.datacamp.com/production/repositories/5756/datasets/d0251f26117bbcf0ea96ac276555b9003f4f7372/investment_annual_summary.csv\")\ninvestment_services_projects <- read_csv(\"https://assets.datacamp.com/production/repositories/5756/datasets/bcb2e39ecbe521f4b414a21e35f7b8b5c50aec64/investment_services_projects.csv\")\n```\n\n\n## Datasets \n\n### Investment Annual Summary\n\nThe `investment_annual_summary` dataset provides a summary of the dollars in millions provided to each region for each fiscal year, from 2012 to 2018.\n```{r investment-annual-summary}\ninvestment_annual_summary\n```\n\n### Investment Projects in Brazil\n\nThe `investment_services_projects` dataset provides information about each investment project from 2012 to 2018. Information listed includes the project name, company name, sector, project status, and investment amounts.\n```{r brazil-investment-projects}\nbrazil_investment_projects <- investment_services_projects %>%\n  filter(country == \"Brazil\") \n```\n\n### Investment Projects in Brazil in 2018\n\n```{r brazil-investment-projects-2018}\nbrazil_investment_projects_2018 <- investment_services_projects %>%\n  filter(country == \"Brazil\",\n         date_disclosed >= \"2017-07-01\",\n         date_disclosed <= \"2018-06-30\") \n\nbrazil_investment_projects_2018\n\nbrazil_investment_projects_2018_total <- brazil_investment_projects_2018 %>%\n  ___(sum_total_investment = ___(___, na.rm = ___)) \n```\n\nThe total investment amount for all projects in ___ in the ___ fiscal year was ___ million dollars.\n\n\n"}