Tasks

  1. Install SWIRL courses that we’ll need for the next sessions. You should already have installed the package swirl. If not, you need to do that first (see previous session’s slides). Next, install the interactive R courses as described on the next slide.
  2. Complete lessons 1 and 4 of SWIRL Course “R Programming”. Lesson 3 is optional, lesson 2 should be skipped.
  3. Take a look at the last 5 tweets of WZB_Berlin
    1. Create two vectors retweets and likes that contain the respective numbers from the last 5 tweets
    2. Create a third vector tweet_ids that contains the numbers 1 to 5 as identifiers for the tweets
    3. Check the data type of all three vectors using the function class(...)
    4. Look at 5 more tweets, append the respective data to the vectors
    5. Create a dataframe tweetstats from the three vectors
    6. Add an additional variable/column to tweetstats named interactions which is the sum of retweets and likes for each observation
  1. As in the previous session’s tasks, we’ll work with the cats dataset from the package MASS.
    1. Load the package and the dataset.
    2. How do you bring up the dataset documentation / help for the dataset?
    3. Identify the number of rows and columns in the dataset by using the respective R functions.
    4. Identify the column names using the respective R function.
    5. What are the data types of the columns in the dataset? Again, use class(...) to answer this question.
    6. What if you recorded two more variables: Age and whether the cat has heart problems. Which data types would you choose for each variable?
    7. Create a new column wt_ratio which is the ratio of heart and body weight. Make sure to bring both variables to a common unit of measurement (i.e. both in grams or kilograms).

Notes on installing SWIRL courses

First, load the package:

library(swirl)

If an error message shows up, then you probably didn’t install the package. You need to do this first with the command install.packages('swirl').

Next, install three courses with the follwing commands (see next slide, in case one of this commands fails):

install_course_github("swirldev", "R Programming")
install_course_github("swirldev", "Getting and Cleaning Data")
install_course_github("swirldev", "Exploratory Data Analysis")

You can start SWIRL with the following command which will guide you through the first steps:

swirl()

One additional note: When you receive the question “Would you like to receive credit for completing this course on Coursera.org?”, select “No”.

In case installing a SWIRL course fails, do the follwing:

  1. Download the ZIP file swirl_courses-master.zip from the following address: https://github.com/swirldev/swirl_courses/archive/master.zip
  2. Move this file to your current working directory (you can find that out via getwd()).
  3. Execute the following commands:
install_course_zip("swirl_courses-master.zip", multi=TRUE,
                   which_course = "R Programming")
install_course_zip("swirl_courses-master.zip", multi=TRUE,
                   which_course = "Getting and Cleaning Data")
install_course_zip("swirl_courses-master.zip", multi=TRUE,
                   which_course = "Exploratory Data Analysis")