Write a loop that calculates 12-factorial
#quickly check to obtain the answer for 12-factorial by using the factorial function
factorial(12)
## [1] 479001600
#create an f variable which will hold the value of 1
#create the for loop with a sequence of 1 through 12 since the factorial of 12 is obtained by multiplying every number up until 12
#since the f variable carries a value of 1 the loop tells R to multiply 1 against the sequence and apply each answer to the index variable
f <- 1
for(i in 1:12){
f <- f*((1:12)[i])
print(f)}
## [1] 1
## [1] 2
## [1] 6
## [1] 24
## [1] 120
## [1] 720
## [1] 5040
## [1] 40320
## [1] 362880
## [1] 3628800
## [1] 39916800
## [1] 479001600
Show how to create a numeric vector that contains the sequence from 20 to 50 by 5
#variable entitled numvec will host the sequence
numvec <- seq(from=20, to=50,by = 5)
#display the sequence
numvec
## [1] 20 25 30 35 40 45 50