R Markdown

Hello, this is my solution for R Bridge workshop Assignemnt 1:

1. Write a loop that calculates 12-factorial.

Result <- 1
for(i in 2:12){
  Result <- Result*i
}
print(Result)
## [1] 479001600

2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.

You can also embed plots, for example:

numericVector <- seq(20,50,5)
print(numericVector)
## [1] 20 25 30 35 40 45 50

3. Create the function “factorial” that takes a trio of input numbers a, b, and c and solve the quadratic equation. The function should print as output the two solutions.

factorial <- function (a, b, c)
{
  discriminant <- (b^2) - (4*a*c)
  print(discriminant)
    if(discriminant > 0)
    {soln1_pos <- (-b + sqrt(discriminant)) / (2*a)
      soln1_neg <- (-b - sqrt(discriminant)) / (2*a)
      return(paste("The two real solutions are ", soln1_pos, "and", soln1_neg, "."))}
    else if(discriminant == 0)
      {soln2 <- (-b) / (2*a)
    return(paste("The only solution is", soln2))}
    else 
     return(paste("The equation has complex solutions"))}
factorial (1,-2,-4)
## [1] 20
## [1] "The two real solutions are  3.23606797749979 and -1.23606797749979 ."