Welcome to this online introduction to R provided by the Section of Biostatistics, Department of Public Health, University of Copenhagen. The introduction was made with assistance from Anne Lyngholm Sørensen and Mads Møller Pedersen.

The purpose of introducing R online is to give you a good start working with R and to make sure that you have obtained some familiarity wiht R before the start of your course in biostatistics. There are many excellent introductory R courses available online. However, these courses are usually not targeted health researchers and are often very comprehensive. The intention of providing our own introduction to R is to give you a relatively short introduction matching the needs for our courses in biostatistics.

In this introduction we guide you through how to install R, how to interact with R and how to use R for simple calculations. We will explain how data is stored in R, how to load data and how to define new variables. You will also be introduced to some of the most common functions used for descriptive analysis and graphics.

If you need our help when working with the activities, you may reach us using this this form. You may also use the form if you find any errors (code or links that does not work, errors in quizzes, missing figures etc), or to give feedback and suggestions on how we can improve the introduction.

We expect that the time needed to work on this introduction ranges from 7 to 16 hours depending on your technical skills and familiarity with R. At the beginning of each chapter we specify the number of hours we expect you to spend to complete the activities. Please let us know, using the above link for feedback, whether these numbers are wrong.

Have fun with the activities!
/ Susanne Rosthøj
Associate Professor
Section of Biostatistics
Department of Public Health
University of Copenhagen

Organization of Introduction to R

The introduction is organized in a series of chapters. The sidebar in the pane to the left shows the table of contents and can be used to navigate between the different chapters and their subsections. Each chapter contains introductory material (text and videos) and exercises. Learning R requires, as with any language, that you train how to use it. We therefore suggest that you run all the commands described in the chapters and complete the exercises in each chapter.

The introduction consists of 7 chapters and an appendix. We recommend that you follow the course chronologically as later chapters may use the contents from earlier chapters.

If you are short on time you may skip some parts before your course in biostatistics starts:
  • Chapter 4 on loading of data: Sections 4.1-4.6 are important as you have to be able to load a data set in to R before the course starts. Play around with the different data files to find out how to load data. You may skip Chapters 4.7-4.8, these will be more useful when you start working with your own data.
  • Chapter 6 is very important! If you have some familiarity working with R you may go straight to Chapter 6.4 and 6.5. If you have no or little experience with R and insufficient time, skip Chapter 6.5.
  • In the Graphics section in Chapter 7 you find a large training activity that you might find a bit difficult. If you don’t have enough time before the course starts, you may postpone this activity (don’t postpone chapter 7.1).

Tips regarding the videos:

  • Watch the videos in Full HD (use the gear icon in the lower right corner) and in full screen.
  • Read the short summaries of the videos following each video lesson.
  • Try some of the code yourself!

Tips regarding the exercises:

In each chapter you find a series of exercises / quizzes to be solved using R. For each exercise you will find the solution or a link to a quiz allowing you to test your result. NB: The site hosting the quizzes (Canvas) only supports the current and first previous major releases of the browsers (find a complete list of supported browsers here) . If you are using an older version of a browser, you may not be able to use the quizzes.

  • Use R to complete the quizzes - the trial and error method is a great way of learning how to interact with R.
  • Submitting your results in the quizzes you will receive feedback on whether your results were right or wrong. Further, some of the quizzes will contain detailed explanatory solutions including R code and alternative solutions. Therefore always scroll to the bottom of the page with feedback.

Using this course as an encyclopedia:

You can use this course as an encyclopedia in two ways:

  1. Use the search icon located in the top left of the header to search for specific keywords. Note that the menu to the left will shrink to contain only the chapters where you can find the word you are searching for.
  2. Pay attention to Appendix B where you will find an overview of some of the most frequently used R commands. As a new user, we recommend that you use the overview to search for commands rather than using google.