This assignment covers some basic, yet very important concepts. Believe it or not, all of the more complicated and sophisticated computing techniques in this course and beyond are built upon a small set of operations like the ones we are learning.
Try to keep in mind the big-picture concepts listed above as you work through the technical exercises. They will help you understand and appreciate how the technical skills (which will get more technical) relate to the larger picture!
During this and the following several labs, you’ll become familiar with all of these terms. It will be essential for you to know what each of them means as you continue to build your R and computing skill set:
Operating system
Application
Graphical user interface (GUI)
Command line
Hard drive and memory (and what is the difference?)
Filesystem concepts
Files and directories
Subdirectory/subfolder
Path
Absolute and relative paths
Root directory
File concepts
File name
Text file
Zip/archive file
File extension and association
R considers any text contained within quotes to be a string of literal text. It won’t attempt to interpret its meaning.
R will attempt to interpret any non-quoted text you type into the R Console (or a script file) as an expression to be evaluated.
Work through the chapters of the Introduction to R course in DataCamp.
The lecture course will have a set of basic questions regarding the concepts in the Intro to R course, the lab will build on these with more technical questions.
I suggest you complete the lecture assignment before beginning this lab assignment.
To keep our lab files organized, we’ll store them in a subdirectory of our main course folder.
From now on, you’ll use always the course RProject to do your
work in RStudio. When you start up RStudio, always check the upper right
corner of the RStudio window to verify that you have the correct
RProject
Finding and loading files into R is one of the greatest initial hurdles for new R users.
To that end everybody will set up a common folder structure for the course so that it is easier to collaborate with classmates and to ask questions.
After you’ve created your course directory structure and created your
course RProject (instructions are in the software setup lecture
assignment) create a labs
subdirectory of your main course
folder. Within the labs
folder, create a subdirectory
called lab_01
.
You’ll create a new subdirectory of labs
for each lab
assignment.
To do your work on labs 1 and 2, you should create R script files. R scripts are text files that contain instructions to be sent to the R console.
lab_01
directory. I
suggest giving it a descriptive filename like lab_01.R
.
.R
.Run the following two lines of code in the console.
c(1, 2, 3)
"c(1, 2, 3)"
Run the following two lines of code in the console and consider the differences:
c_1 = c(1, 2, 3)
c_2 = "c(1, 2, 3)"
Create a numeric vector of length 6 called my_vec. It should contain the integers from 1 to 6. Build a matrix using the following code:
mat_1 = matrix(my_vec, nrow = 3)
Q5 (1 pt.): What are the dimensions of the matrix (i.e. how many rows and columns)?
Q6 (2 pts.): Write R code to retrieve the element of mat_1 that has a value of 3.
You will use my_vec from the previous question again.
Create a matrix mat_2 that has two
rows and three columns using
my_vec
. Do not use the c()
or
rep()
functions.
Create a matrix mat_3 that has three
rows and two columns using
my_vec
. Do not use the c()
or
rep()
functions.
mat_2
.mat_3
.my_vec
?my_vec
, create a
matrix, mat_4
. mat_4
must have a total number
of elements that is not a multiple of 6.my_vec
in
mat_4
?Subsetting objects is a key skill when working with R.
Typical questions we might ask:
Create a list, named my_list_1 with following three elements:
Do you recall how to do this from the DataCamp course?
Name the elements in my_list_1:
NOTE: Yes they are out of order!!!
Run the following 8 lines of code.
my_list_1[[1]]
my_list_1[[as.numeric("1")]]
my_list_1[["1"]]
my_list_1[["one"]]
my_list_1$one
my_list_1$"one"
my_list_1$1
my_list_1$"1"
Q12 (8 pts.): For each of the 8 lines, answer
the following: A. Did the line return a 1: value, 2: error, or 3:
NULL
? B. What type of subsetting operation was used (or
attempted)? C. If it did not return an error describe,
in ordinary English, a plausible explanation of how R could have
performed the subsetting.
Q13 (2 pts.): Identify which lines produced the
string output "five point two"
and explain why.
Q14 (1 pt.): Identify which lines produced
NULL
output and explain why.
Compile your answers to all 14 questions into a pdf document and submit via Moodle.