1/200 * 30
[1] 0.15
59 + 73 + 2) / 3 (
[1] 44.66667
sin(pi / 2)
[1] 1
In this course, you will not have to download R or RStudio, which are software tools used to implement the R coding language. Since our focus is not for you to become expert coders, but rather to expose you to the data science work flow, we are going to do all your coding in interactive tutorials like this one.
For this first experience, I just want you to get used to the format. This tutorial directly mirrors the R for Data Science textbook “Whole Game > 2 Workflow:basics” chapter that you were assigned to read this week. As you’re reading, use this page to run the code that appears in the chapter.
A couple vocabulary words:
code chunk: these are sections in your tutorials that contain code that is for you to view and investigate, but not necessarily run
WebR code chunk: these are sections in your tutorials that contain an interactive code chunk that allows you to edit and run the code in the section
These are examples of code chunks:
Notice the output of the code is printed below the chunk, and you are not able to edit the chunk.
Here is an example of a WebR code chunk:
In this type of code chunk, you can click in the chunk and edit what is written there. You might have noticed, nothing gets printed when you click “Run Code”. Try writing “x” on the next line and running the code to see what happens.
Let’s try another example. In the code chunk below, add the code from the text that demonstrates basic arithmetic on vectors. Click “Run Code” and see if you get the same result.
FYI: vectors are a type of data structure that holds elements of the same type–the primes object we create below is a vector of numeric values.
Can you edit the names of the objects and add comments below to make the code more effective?
Try exploring the sample() function in the WebR code chunk below.
Pro-tip: if you want to find out more about how to use a function you can type “?” in front of it to view the help information associated with it.
Try the exercises from the text below. When you have completed them share a screenshot of your outputs for each question to get full points on your homework assignment for this week.
Why does this code not work?
Edit the code so that it runs properly and provide a written response to the question as a comment in the WebR code chunk.
Tweak each of the following R commands so that they run correctly:
We will skip this one since it’s specific to RStudio.
Look at the following lines of code. Which of the two plots is saved as mpg-plot.png
? Why?
Write your response as a comment in the WebR code chunk.
2.2 Comments
Try adding a comment in the WebR code chunk below and running it to see what happens.