This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#### Q1
x <- 12
factorial_x <- 1
for (i in 1:x) {
factorial_x <- factorial_x * i
}
print (factorial_x)
## [1] 479001600
#### Q2
a <- seq(from=20, to=50, by=5)
print(a)
## [1] 20 25 30 35 40 45 50
factorial_abc <- function(a,b,c){
delta = b^2 - (4*a*c)
if (delta<0){
return(paste0("the equation has no real roots"))
}
else if(delta>0) {
root1 = (-b + sqrt(delta))/(2*a)
root2 = (-b - sqrt(delta))/(2*a)
return(paste0("root1 ", root1, " root2 ", root2))
}
else {
root1 = (-b) / (2*a)
return(paste0("this equation has only one root", root1))
}
}
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.