Lecture 1: Introduction
August 3, 2026
Welcome to PSTAT 10 Data Science Principles! ๐
R and SQL. We will cover descriptive statistics, distributions, and graphics in R, as well as relational database management systems, including the relational model, relational algebra, database design principles, and data manipulation using SQL.
I am being assisted this term by the following wonderful teaching assistants:

Abhijit Brahme

Siyu Chen
Communication Guidelines:
Grading Structure
Worksheet & Assignment Submissions
๐ Final is written in-person for 11AM Thursday September 10th in Theater and Dance West.
The following is our tentative course outline:
Throughout the course we will be programming in R. In weeks 4 and 5 we will also be using SQL to query relational databases.
By enrolling in this course, you agree to abide by the UCSB Academic Integrity Policy. In short, you are expected to avoid the following dishonest behaviors:
Cheating
Plagiarism
Lying
Unauthorized collaboration
Misusing resources
Any violation of these policies will be reported to the Office of Student Conduct and may result in a failing grade for the course.
๐ค You may collaborate on assignments and worksheets, but always write and submit your own documents.
๐ค The use of AI tools such as ChatGPT, Claude and Gemini is permitted as a learning tool.
๐ฃ๏ธ Communication is key! Please let me know about any mitigating circumstances or deadline conflicts as soon as possible!
This course will use the programming language R.
Interactive Development Environment
An interactive development environment (IDE) is an application designed to facilitate writing and running code.
RStudio Interface
.R and are used to write code.tidyverse โ a collection of packages for data manipulation and visualization.
ggplot2 โ a package for creating complex and customizable plots.dplyr โ a package for data manipulation and transformation.tidyr โ a package for tidying and reshaping data.Shiny โ a package for creating interactive web applications.The following functions are used to manage packages in R:
To install a package (e.g. cowsay) use the install.packages() function:
The package should now appear in the Packages tab. To use functions from the package we load them using the library() function:
Helpfully, R also has a manual library management tool which allows us to:

In this course you will be required to use Quarto Markdown documents to generate PDFs for submission.
.qmd.f(x,y) = \frac{1}{2\pi\sigma^2} e^{-\frac{x^2 + y^2}{2\sigma^2}}.
\[ f(x,y) = \frac{1}{2\pi\sigma^2} e^{-\frac{x^2 + y^2}{2\sigma^2}}. \]
To create a Quarto document in RStudio we use the new document button in the top left corner and select Quarto document.
New Quarto Document
Then you will be met with the following pop-up menu asking you to specify the document type.

From here you can specify you want a PDF document and give your document a title and author.
# symbols, with more # symbols indicating a lower level heading.- or * symbols, with indentation indicating sub-lists.$ symbols and block expressions enclosed in $$ symbols.r for R) and a set of curly braces.
--- symbols.Fundamentally, R is a calculator allowing you to perform a wide variety of mathematical computations.
[1] 11
[1] 1
[1] 8
[1] 2
[1] 1024
[1] 7.389056
[1] 2.197225
[1] 3
[1] 8
๐ The use of # has made the text following the computations into a comment, which is not read as code.
help() function or the ? function.
sqrt() write the following in your console:๐ Make sure not to include these functions in your written documents.
02:00
Spend a couple of minutes evaluating the following expressions in R:
\[ \frac{\log_2(256)+2^3}{4^2 - \sqrt{64}}. \]
\[ \exp(4)\times56(\ln(7)-3^3) \]
Hint: Use help() to look up the log, log2 and exp functions.
Below is a list of most important R datatypes:
L suffix.' ') or double quotes (" ") becomes a character."2+3*4", "alphabet".! โ negation operator, returns the opposite of a logical value.& โ and operator, returns TRUE if both logical values are TRUE.&& โ short-circuit and operator, returns TRUE if both logical values are TRUE, but only evaluates the first element of each vector.| โ or operator, returns TRUE if at least one logical value is TRUE.|| โ short-circuit or operator, returns TRUE if at least one logical value is TRUE, but only evaluates the first element of each vector.xor() โ exclusive or operator, returns TRUE if exactly one logical value is TRUE.== โ Equal to!= โ Not equal to> / < โ Greater / less than>= / <= โ Greater / less than or equal to02:00
What will the following logical queries return?
5 > 1010 <= 1013 != 12"Hello" == "Hello""Hello" <= "Hell""Goodbye" != "Hello""Hello" != "Hello" | 5 < 104 <= 2 & 5 <= 123 < 5 < 7Spend 2 minutes evaluating the examples above in R and check your answers.
๐ 9 gives an error because we canโt combine logical expressions without using either & or |.
[1] FALSE
[1] TRUE
[1] TRUE
[1] TRUE
<-
Notice that when you run the code above you receive no output, but the objects will have appeared in your data environment (top right tab).

print() function is used to display the value of an object in the console.
paste() function which allows us to concatenate strings and objects together.๐ Make sure your code is easy to read โ both for graders and for your own error checking โ by documenting with comments and using good structure (such as indentation).
๐ค When naming objects in R keep in mind the following conventions:
๐ Avoid repeating yourself (DRY) โ write a function for any code you find yourself copy-pasting more than once (we will cover functions in a later lecture).
๐ Test and debug incrementally โ run and check your code in small pieces as you write it, rather than all at once, so errors are easier to catch and fix.
๐พ Save your work often!