4 + 3/5^2
## [1] 4.12
set.seed(7)
rnorm(4, mean = 10)
## [1] 12.287247 8.803228 9.305707 9.587707
s1<-sample(1:10,5)
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)
z <- 5
w <-z^2
w
## [1] 25
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)
se<-sqrt(v/n)
return (se)
}
se(c(1,2,3,4,5))
## [1] 0.7071068
f <- function(x){
for(i in 1:10){
res <- x*i
cat(x, '*',i,'=',res,'\n')
}
}
f(4)
## 4 * 1 = 4
## 4 * 2 = 8
## 4 * 3 = 12
## 4 * 4 = 16
## 4 * 5 = 20
## 4 * 6 = 24
## 4 * 7 = 28
## 4 * 8 = 32
## 4 * 9 = 36
## 4 * 10 = 40
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:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
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.