DS 1300 Introduction to Data Science – Introduction (Lecture 1)
QUESTION 1: This is a class about data. What is data?
Data is information
Data is information in a useable form
Data is ever
ywhere
2^70 or a trillion gigabytes
From: https://www.statista.com/statistics/871513/worldwide-data-created/
From Taru Khurana: The Great Wall of China contains 3,873,000,000 bricks. If each Gigabyte in a
Zettabyte were a brick, 258 Great Walls of China could be built.
QUESTION 2: What is data science/data analytics?
Data science is an exciting discipline that allows you to turn raw data into understanding, insight, and knowledge
From IBM: Data science combines the scientific method, math and statistics, specialized programming,
advanced analytics, AI, and even storytelling to uncover and explain the business insights buried in data.
From IBM: Data science is a multidisciplinary approach to extracting actionable insights from the large
and ever-increasing volumes of data collected and created by today’s organizations. Data science
encompasses preparing data for analysis and processing, performing advanced data analysis, and
presenting the results to reveal patterns and enable stakeholders to draw informed conclusions.
https://www.ibm.com/cloud/learn/data-science-introduction
1
NOTE: The Data Science Pipeline. The figure below, taken from R for Data Science (Ch 2)
https://r4ds.had.co.nz/explore-intro.html, shows the “Data Exploration” stage of the data science pipeline.
There are additional steps outside of the data exploration stage.
NOTE: There are a variety of tools that we are going to learn in this class. Specifically, we will focus on
using R, RStudio, and packages. A brief explanation of each follows:
Introduction to R/RStudio Activity
1. (This step is optional but is meant to help you manage files for this class.) Create a folder for this class.
Using either Windows Explorer (Windows) or Finder (Mac), navigate to where you wish to store the
folder. Create a new folder called DS_1300. I would also recommend creating subfolders such as one for
Lectures, one for Labs, and one for HW.
2
2. From Canvas Module 1, download the files BirthWt. and Basics.R (I would suggest saving them in the
newly created folder from Step 1.
3. Open RStudio.
4. Identify the four windows of RStudio.
Bottom Left: Console window - we can type small segments of code and run here; we will also
see the results of code that we run in this window
Upper Left: Scripting window - this is where we will write code that we wish to save for the future
Upper Right: Environment window - show the names of objects that you have stored
Bottom Right: Output or Plots window - graphics will show up here
NOTE: Upon using RStudio for the first time, you may only see 3 windows. If this is the case, choose File
-> New File -> R Script. This will display the 4th window.
IDEA: R may be used as a calculator by entering calculations directly into the Console window.
5. In the Console window, look for the > symbol. This serves as the prompt for where you can type.
In the Console window, type one line at a time and press “Enter” or “Return.”
1/2-4
1/2-4
1 / (2-4)
1-2/4
sin(pi/2)
NOTE: sin() is a function call. “sin” is the name of the function and the part inside the parentheses (i.e,
pi/2) is called an argument of the function. In this case, “sin” is the sine function from trigonometry.
6. What action does each of the following functions perform?
sqrt(36)
seq(1,10)
3
IDEA: We often wish to associate values with objects in R. We can accomplish this using assignment
statements of the form:
object_name <- value
OR
object_name = value
NOTE: When reading that code say “object name gets value” in your head.
7. Enter each line of code in the Console window:
ans1 <- 3 * 4
ans2 <- 2 ^ 4
NOTE: When using an assignment statement, the object will be stored and shows up in the Environment
window. These stored values can be used in subsequent calculations.
8. We can check the values of objects by typing the object name and pressing “Enter” or “Return” in the
console. We can also perform calculations using the stored values.
ans1
ans2
ans1 + ans2
9. What happens when you run:
Ans1
NOTE: There’s an implied contract between you and R: it will do the tedious computation for you, but in
return, you must be completely precise in your instructions. Typos matter. Case matters.
NOTE: A note on object names. Object names must start with a letter, and can only contain letters,
numbers, underscores (_) and periods (.). You want your object names to be descriptive, so you’ll need a
convention for multiple words. We recommend snake_case where you separate lowercase words with _.
4
IDEA: As our code becomes more complex, we move away from directly entering it in the console. We
often type our code in the Scripting window so that we can save the code for future use.
IDEA: Objects are not limited to simple numerical values.
10. Enter the following pieces of code in the Scripting window. Then, run the code.
A <- matrix(seq(1,10), nrow=2, ncol=5)
x <- “Hello World!”
A
x
NOTE: Typing the code in the Scripting window does not execute the code. To run a single line, press
CTRL + ENTER (Windows) OR CMD + RETURN (Mac). You can also run the line by highlighting the
line and selecting the Run button.
NOTE: Quotes and parentheses (or other grouping symbols must occur in pairs). Quotation marks and
parentheses (or other grouping symbols) must always come in a pair. RStudio does its best to help you,
but it’s still possible to mess up and end up with a mismatch. If this happens, R will show you the
continuation character “+” in the console.
11. Enter the line shown below in the Scripting window and run it:
y <- “Hello World!
NOTE: The + symbol in the Console window tells you that R is waiting for more input; it doesn’t think
you’re done yet. Usually that means you’ve forgotten either a " or a ). Either add the missing piece or
press ESCAPE to abort the expression and try again.
IDEA: We can save the code that we have entered in the Scripting window for a future session. Select File
-> Save As to save your file for future work.
IDEA: Packages and libraries play an important role in R. An R package is a collection of functions, data,
and documentation that extends the capabilities of base R.
5
NOTE: We can view the packages that are currently installed by selecting the Package tab in the Plots
window (bottom right window). Packages installed on your computer will be listed and packages that
have a check mark are ready for use in your R session.
12. In the Console window, enter:
library(MASS)
NOTE: After running this code, you should see MASS in the package list and it should have a checkmark.
This means that we can use all of the functionality (functions, data, and documentation) built into the
MASS package.
13. What happens if you enter:
library(ggplot2)
NOTE: We sometimes have to download a package before we can use it. This is accomplished by running
the code shown below:
install.packages(“ggplot2”)
library(ggplot2)
NOTE: The install.packages code will only have to be run one time on your computer; however, you must
use the library command in each R session in which you wish to use the functionality of ggplot2.
6