Using RStudio Worksheet
Directions
Complete the problems on this worksheet with 2–3 other students. You may want to refer to the Getting Started with R and Data Structures in R chapters in the Computational Toolkit for Educational Scientists.
Problem Set I
Use R to compute the answer to the following problems. You can (for now) work in the console or use a script file. This problem set will focus on skills and ideas you learn in the section Getting Started with R.
Compute: \(2 + 3 \times 5\). Does R follow order of operations or not?
Compute: \((3 \times5^2 \div 15)-(5-2^2)\)
Compute: \(\sqrt{~\left\vert3-4\right\vert~}\)
Create a sequence of the numbers 1 and 5. Store this in an object called
one_five
.Create a sequence of all integers between 10 and 1. This sequence should begin at 10 and end at 1. (e.g., \(10,9,8,7,\ldots,1\)). Store this in an object called
my_num
.Use the
length()
function to count the number of elements in theone_five
object. Also use it to count the number of elements inmy_num
.Compute \(\mathtt{one\_five}+\mathtt{my\_num}\). Explain how R is using the two objects to obtain the result it did.
Install the following three packages from CRAN: dplyr, ggplot2 and remotes.
Load the remotes package.
Install the educate package from GitHub.
Problem Set II
Use R to compute the answer to the following problems. For these problems, please work in a script file. This problem set will focus on skills and ideas you learn in Data Structures in R.
Create a new script file. Save it on your computer. When you do this give it a name other than Untitled.
Use the
c()
function to create a vector that includes the number of pets each person in your group has. Name this vectorpets
. (If you have 2 or fewer people in your group, combine your results with another group so that you have at least 3 values.)Create a data frame that includes two columns. The first column will be the first names of everyone in your group (or combined groups). Call this column
first_name
. The second column will be the number of credits each person in your breakout room is taking this semester. Call this columncredits
. Assign this data frame a name so that you can compute on it later. (Feel free to make it a three column data frame by adding thepets
column.)
Problem Set III
Use R to compute the answer to the following problems. For these problems, please continue to work in the script file. This problem set will focus on skills and ideas you learn in Data Structures in R.
Import the comic-characters.csv data into R. Assign this to an object called
comics
. If you use theImport
button to do this, make sure you copy the syntax into your script file.Examine the codebook for the comic-characters.csv data.
Run the syntax
View(comics)
. This should display the imported data in a tab in RStudio. Use the search bar in the tab to search for “Hobgoblin”. How many Hobgoblin characters are there?Use the search bar in the tab to search for “Skrull”. How many Skrull characters are female? (Hint: Click the arrows in the
sex
heading to sort by sex.) How many Skrull characters have brown eyes? What years were Skrull characters part of the Marvel storyline?Run the syntax
mean(appearances)
. You should get an error. Try to figure out why you are getting this error. (Hint: Look at the objects in your environment.) Can you figure out the syntax to find the average number of appearances for a comic character? (Hint: Because there are missing values in this column, you will need to add the argumentna.rm=TRUE
in themean()
function.)