R Markdown exercises part 1

July 29, 2017

(This article was first published on R-exercises, and kindly contributed to R-bloggers)


R Markdown is one of the most popular data science tools and is used to save and execute code, create exceptional reports whice are easily shareable.

The documents that R Markdown provides are fully reproducible and support a wide variety of static and dynamic output formats.

Using markdown syntax, which provides an easy way of creating documents that can be converted to many other file types, while embeding R code in the report, so it is not necessary to keep the report and R script separately. Furthermore The report is written as normal text, so knowledge of HTML is not required. Of course no additional files are needed because everything is incorporated in the HTML file.

Before proceeding, please follow our short tutorial.

Look at the examples given and try to understand the logic behind them. Then try to solve the exercises below using R and without looking at the answers. Then check the solutions.
to check your answers.

Exercise 1

Create a new R Markdown file (.Rmd) in RStudio.

Exercise 2

Insert a YAML Header with title, author and date of your choice at the top of your .Rmd script.

Exercise 3

Display the summary of “cars” dataset in your report. HINT: Use summary().

Exercise 4

Make a plot of the “cars” dataset under the summary you just created. HINT: Use plot().

Exercise 5

Create a small experimental dataframe and dipslay it in your report. HINT: Use data.frame().

Learn more about reporting your results in the online course: R for Data Science Solutions. In this course you will learn how to:

  • Build a complete workflow in R for your data science problem
  • Get indepth on how to report your results in a interactive way
  • And much more

Exercise 6

Hide the code from your report. HINT: Use echo.

Exercise 7

Load the package “knitr” in your .Rmd file. and hide the code chunk. HINT: Use echo.

Exercise 8

Hide the warning message that appeared in your report. HINT: Use warning.

Exercise 9

Set fig.width and fig.height of your plot to 5.

Exercise 10

Change the file format of your plot from .png to .svg. HINT: Use dev.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)