## ----setup, include=FALSE----------------------------------------------------------
knitr::opts_chunk$set(echo = TRUE, 
                      warnings = FALSE, 
                      mmessage = FALSE)


## ----------------------------------------------------------------------------------
1+2
3^6
sqrt((20-19)^2 + (19-19)^2 + (19-18)^2)/2
12345*54312


## ----------------------------------------------------------------------------------
X <- 5  	# sets X equal to 5 


## ----------------------------------------------------------------------------------
X


## ----------------------------------------------------------------------------------
X*2
X^X


## ----------------------------------------------------------------------------------
Fred <- 5
Nancy <- Fred*2
Fred + Nancy


## ----------------------------------------------------------------------------------
X <- c(3,4,5)  	# sets X equal to the vector (3,4,5)
X


## ----------------------------------------------------------------------------------
X + 1
X*2
X^2
((X+X^2/2)/X)^2


## ----------------------------------------------------------------------------------
counts <- c(150,125,105,110,140)


## ----------------------------------------------------------------------------------
k <- length(counts)
sum(counts)/k


## ----------------------------------------------------------------------------------
mean(counts)


## ----------------------------------------------------------------------------------
counts - mean(counts)


## ----------------------------------------------------------------------------------
sum((counts - mean(counts))^2)


## ----------------------------------------------------------------------------------
sqrt(sum((counts - mean(counts))^2) / (k-1))


## ----------------------------------------------------------------------------------
sd(counts)


## ----------------------------------------------------------------------------------
mean(counts) + c(-2,2)*sd(counts)


## ----------------------------------------------------------------------------------
Y <- c(1,2,3)
data.frame(X,Y)


## ----------------------------------------------------------------------------------
mydata <- data.frame(X,Y)


## ----------------------------------------------------------------------------------
ncol(mydata) # ncol() gives us a number of columns that this data frame has
names(mydata) # names() lists all column names that this data frame has 


## ----------------------------------------------------------------------------------
mydata$X
mydata$Y


## ----echo = FALSE------------------------------------------------------------------
SeaLions <- read.csv("SeaLions.csv")


## ----eval = FALSE------------------------------------------------------------------
## SeaLions <- read.csv("insert the directory instead of this sentence/SeaLions.csv")


## ----------------------------------------------------------------------------------
is(SeaLions) # tells what type of files we have
names(SeaLions) # tells us the names of all the columns
head(SeaLions) # shows the first several rows of the dataframe


## ----------------------------------------------------------------------------------
Length <- SeaLions$Length
Weight <-SeaLions$Weight
Island <- SeaLions$Island
Sex <- SeaLions$Sex


## ----------------------------------------------------------------------------------
range(Length) # range
median(Length) # median
mean(Length) # mean
var(Length) # variance
sd(Length) # standard deviation


## ----echo = -1---------------------------------------------------------------------
hist(Length)


## ----echo = -1---------------------------------------------------------------------
boxplot(Weight ~ Sex)


## ----echo = -1---------------------------------------------------------------------
plot(Length, Weight)

