Data Science VC follow up: Intro to R and Statistics for the Rookie Part 1

I’ve decided to hold a five week introductory statistics and R course. Here, I am sharing the slide deck and the code. The video will go up on our YouTube Data Science Virtual Chapter channel, which is accessible from here.

In the first week, we talked about the relationship between statistics and data visualisation, and how it is extremely useful to have a good grounding in both topics. The slides are here, followed by the code:

The R code can be copied and pasted into your RStudio file:

# Loads sample datasets
data()

# Let’s look at the data
# This command tells you the metadata. What does R see, when it sees ‘iris’?
str(iris)

# What are the attributes?
# This gives us more information.
attributes(iris)

# Let’s see more of the data
iris

class(iris)
# A data frame has columns which can have different types.
# The column names and types constitute the schema.
# how do we know what is in our data frame?

# Column Names
colnames(iris)

# how can we see data in one of the columns?
iris$Petal.Length
# or we could also use iris[,3] to get the same column data.

iris[,3]
# of course, we want to visualise the data.
# Let’s do a simple scatter plot.

# How can we see the first five rows?
iris[1:5,]

# how can we see the Petal Length of the first 5 rows?
iris[1:5, “Petal.Length”]

# This shows us some of the descriptive statistics of each variable
summary(iris)

table(iris$Species)

# Let’s have some dataviz fun!
plot(iris$Petal.Length, iris$Petal.Width, main=”Anderson’s Iris Data”)
# You can now see the plot appear in the right hand side frame of RStudio.
# we can make it slightly more interesting
plot(iris$Petal.Length, iris$Petal.Width, pch=23, bg=c(“orange”, “blue”, “green”) [unclass(iris$Species)], main=”Anderson’s Iris Data”)

# we can make it even more interesting
pairs(iris[1:4], main = “Anderson’s Iris Data”, pch = 23, bg = c(“orange”, “green”, “blue”)[unclass(iris$Species)])
# pie charts!
pie(table(iris$Species))

# ooh, 3D!

library(scatterplot3d)
scatterplot3d(iris$Petal.Width, iris$Sepal.Length, iris$Sepal.Width)

# ooh, even more 3D!
library(rgl)
plot3d(iris$Petal.Width, iris$Sepal.Length, iris$Sepal.Width)

#Save your work!

savehistory(“~/Topic 1 Getting familiar with R A.Rhistory”)