Getting started in R with swirl

Basic functions in R

During this course we’ll be using the swirl package for R in order to illustrate some key concepts. The swirl package was developed by data scientists, and turns the R console into an interactive learning environment. It can be used free of charge.

The course we are using is called R Programming, and was developed by Dr. Roger D. Peng. He is a Professor of Biostatistics at the Johns Hopkins Bloomberg School of Public Health.

Using swirl will also give you the opportunity to be completely immersed in an authentic R programming environment. In this programming assignment, you’ll have the opportunity to practice some key concepts in R.

  • swirl requires R 3.0.2 or later. If you have an older version of R, please update before going any further. If you’re not sure what version of R you have, type R.version.string at the R prompt. You can download the latest version of R from https://www.r-project.org/.

Install swirl

Since swirl is an R package stored on CRAN, you can easily install it (or other packages) by entering a single command from the R console:

  • (r)
    install.packages(“swirl”)

If you’ve installed swirl in the past make sure you have version 2.2.21 or later. You can check this with:

  • (r)
    packageVersion(“swirl”)

Load swirl

Every time you want to use swirl, you need to first load the package by using the library function. From the R console:

  • (r)
    library(swirl)

Type the following from the R prompt to install this course:

  • (r)
    install_from_swirl(“R Programming”)

Type the following from the R console to start swirl:

  • (r)
    swirl()

Then, follow the menus and select the R Programming course when given the option. You should complete the following lessons:

1: Basic Building Blocks
2: Workspace and Files
3: Sequences of Numbers
4: Vectors
5: Missing Values
6: Subsetting Vectors
7: Matrices and Data Frames
15: Base Graphics

This will demonstrate the basics of R, how it operates and gets you started on data manipulation.

Need help?

  • If you can’t figure out the answer after multiple tries, use the ? option in RStudio to get tips.

  • If all else fails, consider using AI to find the answer you are looking for.