## RUSIS Lab 1


### Section 2: R
### Subection 2.2: Help

?help
help(help)
?help.search
?help.start

?plot
plot(sin, -pi, 2 * pi)


### Subsection 2.3: Basic Arithmetic

5 + 2
5 - 2
5 * 2
5 / 2
5^2

5 %% 2  # 5 mod 2
5 %/% 2 # whole number times 2 goes into 5 (int division)
5e2     # 5 * 10^2
5e-2    # 5 * 10^(-2)

exp(5)
pi
sqrt(5)
log(5)


### Subsection 2.4: Vectors

c(5, 2) + c(4, 6)
c(5, 2) - c(4, 6)
c(5, 2) * c(4, 6)
c(5, 2) / c(4, 6)
c(5, 2) ^ c(4, 6)
c(5, 2) %% c(4, 6)
c(5, 2) %/% c(4, 6)
c(5, 2) %*% c(4, 6)

c( c(5, 2), c(4, 6))


### Subsection 2.5: Matrices

matrix( c(5, 2, 4, 6), nrow = 2, ncol = 2)
matrix( c(5, 2, 4, 6), nrow = 2, ncol = 2, byrow = TRUE)
t( matrix( c(5, 2, 4, 6), nrow = 2, ncol = 2))
rbind( c(5,4), c(2,6) )
cbind( c(5,2), c(4,6) )


### Subsection 2.6: Storing Variables

name <- "Jaime Ramos"
a <- 5
a * a
a * 2
factor(a)


### Subsection 2.7: Variable Name

a <- matrix( c(1, 0, 0, 1), 2, 2)
b <- matrix( c(1, 2, 3, 4), 2, 2)
a + b
a - b
a * b
a / b
a %% b
a %/% b
a %*% b


### Subsection 2.8: The Scipting Window

int_rate <- 0.02
n <- 10
principal <- 1500
payment <- principal * int_rate / (1 - (1 + int_rate)^(-n))


### Subsection 2.9: Functions

'+'(5,6)
'^'(5,6)
matrix(nrow = 2, data = c(5, 2, 4, 6), ncol = 2)


### Subsection 2.10: Coin Flipping

a <- rbinom(n = 1000, size = 1, prob = .5)
mean(a)
sum(a)/1000
a %*% rep(1/1000,1000)

plot(1:1000, cumsum(a) / 1:1000)