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:
4+3/5^2
## [1] 4.12
set.seed(7)
x<-rnorm(4,mean=10)
x
## [1] 12.287247 8.803228 9.305707 9.587707
s1<-sample(1:10,5)
s1
## [1] 6 8 9 3 10
sample(1:10,5, replace=TRUE)
## [1] 8 10 3 4 8
mean(sample(1:10,5))
## [1] 5.6
plot(x=sample(1:10,5),y=sample(1:10,5),main='Five random points',xlab='X values',ylab='Y values')
z<- 5
w<-z^2
w
## [1] 25
i<-(z*2+45)/2
i
## [1] 27.5
rm(z,w,i,s1)
max(4,5,6,12,-4)
## [1] 12
max('ab','cd','s')
## [1] "s"
max(sample(1:100,30))
## [1] 100
exists('se')
## [1] FALSE
exists('mean')
## [1] TRUE
se<-function(x){
v<-var(x)
n<-length(x)
return(sqrt(v/n))
}
se(c(1,2,3,4,5))
## [1] 0.7071068
f<-function(x) {
for(i in 1:10){
res<-x*1
cat(x,'*',i,'=',res,'\n')
}
}
f(4)
## 4 * 1 = 4
## 4 * 2 = 4
## 4 * 3 = 4
## 4 * 4 = 4
## 4 * 5 = 4
## 4 * 6 = 4
## 4 * 7 = 4
## 4 * 8 = 4
## 4 * 9 = 4
## 4 * 10 = 4