Installing cowsay

install.packages("cowsay")

Use :: to access the say function in the cowsay package.

cowsay::say("Welcome to PSTAT 10!", by = "cow")
## 
##  ----- 
## Welcome to PSTAT 10! 
##  ------ 
##     \   ^__^ 
##      \  (oo)\ ________ 
##         (__)\         )\ /\ 
##              ||------w|
##              ||      ||

Or load the cowsay package so that all functions are available.

library(cowsay)
say("Now we don't need the double colon operator", by = "cow")
## 
##  ----- 
## Now we don't need the double colon operator 
##  ------ 
##     \   ^__^ 
##      \  (oo)\ ________ 
##         (__)\         )\ /\ 
##              ||------w|
##              ||      ||

Uninstall a package:

remove.packages("cowsay")

R as a calculator (slide 22)

(5^7 - 2 * sqrt(4)) / log(100, base = 2)
## [1] 11758.38

Vectors (slide 34)

x <- c(1, 3, 5, 6)
scores <- c(8, 7, 8, 10, 5)
mean(scores)
## [1] 7.6
sum(scores) / length(scores)
## [1] 7.6

It is better to call length in the denominator instead of hard-code the number 5. This is because if we add more scores, the denominator would still be right.

median(scores)
## [1] 8
names(scores) <- c("Bob", "Alice", "Alex", "Juan", "Amy")
scores
##   Bob Alice  Alex  Juan   Amy 
##     8     7     8    10     5
scores[2]
## Alice 
##     7
scores["Alice"]
## Alice 
##     7
scores[c("Amy", "Alice")]
##   Amy Alice 
##     5     7
scores[-5]
##   Bob Alice  Alex  Juan 
##     8     7     8    10