## Create variable `my_name` that is equal to your first name and print it
my_name <- "Garrett"
cat("I am", my_name, "\n")
## I am Garrett
## Sometimes you may use "print" instead, this prints just the value:
print(my_name)
## [1] "Garrett"
## 1.1.1
## Create a numeric variable my_age that is equal to your age

Age <- 28
## 1.1.2
## How many seconds is there in a year?  Compute this number!
## Assign it to a suitably named variable and print the result with a
## informative message

Seconds <- 60
Minutes <- 60
Hours <- 24
Days <- 365

secondsInYear <- Seconds*Minutes*Hours*Days
secondsInYear
## [1] 31536000
cat("There are", secondsInYear, "seconds in a year")
## There are 31536000 seconds in a year
## 1.1.3
## What is your age in seconds?  Use the variable my_age
## you computed
## above and seconds-in-year, and compute it.  Assign the result to a
## suitably named variable and print it.

secondsInAge <- Age*secondsInYear
cat("I am", secondsInAge, "seconds old")
## I am 883008000 seconds old
# 1.1.4
## How many seconds is a typical human lifetime?
##
## Note: it is your task to find a good value for “typical” human lifetime!
averageAge <- 77.28
cat("The average American lives a total of", secondsInYear*averageAge, "seconds in their lifespan.")
## The average American lives a total of 2437102080 seconds in their lifespan.
## The rest of the questions are in the pdf.  You do not need to copy the questions
## here, but please add the question numbers!
## Good luck!

## 1.2.1

##m = m0/γ
## where γ =√1 −√ v2c2 (called Lorentz factor). 

v <- .01
c <- 300000
m0 <-  60
Y <- sqrt(1-(v^2/c^2))
options(digits=15)
print(Y)
## [1] 0.999999999999999
m <- m0/Y
cat("The moving mass of a student weighing 60kg moving at .01km/s is",m, "kg") ##moving mass of student weighing 60kg moving at .01km/s
## The moving mass of a student weighing 60kg moving at .01km/s is 60 kg
## 1.2.2
difference <- m-m0 
cat("The difference in moving mass is", difference, "kg") ##difference in moving mass and rest mass of student
## The difference in moving mass is 3.5527136788005e-14 kg
##1.2.3
v2 <- 270000
c2 <- 300000
m2 <- 1.672e-27
Y2 <- sqrt(1-(v2^2/c2^2))
m3=m2/Y2
cat("The mass of a proton moving 270,000km/s is", m3, "kg") ##mass of proton moving 270,000km/s
## The mass of a proton moving 270,000km/s is 3.83583107031579e-27 kg
##1.2.4
magnitude <- m3/m2
cat("The mass of the moving protein is", magnitude, "times greater than stationary")
## The mass of the moving protein is 2.29415733870562 times greater than stationary
##1.3 Extra Credit
#install.packages("Rmpfr")
#library("Rmpfr")
##2.1.1 I am old

I_am_old <- secondsInAge > 650000000 
cat("It is ", I_am_old, "that I am older than 650,000,000 seconds old")
## It is  TRUE that I am older than 650,000,000 seconds old
##2.2 is my age between 650m seconds and 1b seconds

ageBetween <- (secondsInAge > 650000000 & secondsInAge < 1000000000)
ageBetween
## [1] TRUE
print(ageBetween)
## [1] TRUE
## 2.3 Am I older than 500m seconds but not more than 700m seconds old

ThirdQuest <- (secondsInAge > 500000000 & !(secondsInAge > 700000000))
print(ThirdQuest)
## [1] FALSE
## 3.1 Stringr Install
##install.packages("stringr")
##I download stringr as a package and then comment out the install command so
##that it doesn't continue to run every time the document is compiled.

##3.2 Library Stringr
library(stringr)

##3.3/ Template
Template <- ("Hello, my name is <name>, and I am <age> old.")
Template
## [1] "Hello, my name is <name>, and I am <age> old."
##3.4 Name and Age
name <- "Garrett"
age <- as.character(28)

#3.5 Replacing

Replaced_Temp <- str_replace(Template, "<name>", name)

intro <- str_replace(Replaced_Temp, "<age>", age)

print(intro)
## [1] "Hello, my name is Garrett, and I am 28 old."
##3.6 Loud Intro
loud_intro <- toupper(intro)
loud_intro
## [1] "HELLO, MY NAME IS GARRETT, AND I AM 28 OLD."
print(loud_intro)
## [1] "HELLO, MY NAME IS GARRETT, AND I AM 28 OLD."
##3.7 Counting E's
numberOfEs <- str_count(intro, "e")
cat("There are ", numberOfEs, "E's in the intro function")
## There are  3 E's in the intro function
##4.1 Printing i

for(i in 1:10) 
  print(i)
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
## 2.3
##4.2 Printing Squares of i

for(i in 1:10) 
  i2 <- i^2
##4.3 Cat squares of i
for(i in 1:10) {
  i2 <- i^2
  cat(i, "^2 =", i2, "\n", sep=" ")}
## 1 ^2 = 1 
## 2 ^2 = 4 
## 3 ^2 = 9 
## 4 ^2 = 16 
## 5 ^2 = 25 
## 6 ^2 = 36 
## 7 ^2 = 49 
## 8 ^2 = 64 
## 9 ^2 = 81 
## 10 ^2 = 100
##4.4

sum <- 0
for(x in 1:100){
  sum <-  sum + x
}
print(sum)  
## [1] 5050
## 4.5 Factorials
fact <- c()

for(i in 10:1) {
  factorial <- 1
  for(j in 1:i) {
    factorial <- factorial*j}

cat(i, "! = ", factorial, "\n")}
## 10 ! =  3628800 
## 9 ! =  362880 
## 8 ! =  40320 
## 7 ! =  5040 
## 6 ! =  720 
## 5 ! =  120 
## 4 ! =  24 
## 3 ! =  6 
## 2 ! =  2 
## 1 ! =  1
  print(j)
## [1] 1