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:
library(dslabs)
compute_cor<-function(x,y)
{
#\XY
sum(x*y)
#length
n<-length(x)
n
n<-length(y)
n
#n\XY
n*sum(x*y)
#\X
sum(x)
#\Y
sum(y)
#\X\Y
sum(x)*sum(y)
#nominator
nom<-(n*sum(x*y))-(sum(x)*sum(y))
return(nom)
# sum of X and square
n*sum(x^2)
#sum of Y and square
n*sum(y^2)
deno<-(((n*sum(x^2))-(sum(x)^2))*((n*sum(y^2))-(sum(y)^2)))^(0.5)
return(deno)
}
#Q2: create the add numbers:
addNumbers<-function(x,y,w)
{
z<-x+y+w
return(z)
}
#subtraction
subtractNumbers<-function(x,y,o,t)
{
z<-x-y-o-t
return(z)
}
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.