#Addition of 3 Numbers
5+7+3
## [1] 15
#Subtraction of 2 Numbers
10-4
## [1] 6
#Multiplication of 2 Numbers
5*5
## [1] 25
#Division of One Number by Another
12/6
## [1] 2
#Raising a Number to the 4th Power
4^4
## [1] 256
#3rd Root of a Number
(64)^(1/3)
## [1] 4
#Log to the base of a Number
log(4,10)
## [1] 0.60206
#Creating a Vector
c<- c(4,5,6,7,8,9)
#Choosing the 3rd Element in a Vector
c[3]
## [1] 6
#Determining the Length of a Vector
length(c)
## [1] 6
#Creating a Matrix
d<- matrix(c(1,3,5,7,2,4,6,8),nrow=2, byrow=2)
#Adding 5 to Each Number in a Matrix
F<- d+5
F
## [,1] [,2] [,3] [,4]
## [1,] 6 8 10 12
## [2,] 7 9 11 13
#Determining Dimension of a Matrix
dim(F)
## [1] 2 4
#Assigning Values to Characters
k<- 5.25
m<-'frank'
#Determining Data Type
class(k)
## [1] "numeric"
class(m)
## [1] "character"
#Converting Data Types
p<- as.integer(k)
G<-as.character(k)
# k was converted to a character and a character cannot be added to a number so G+5.1 comes up as an error if attempting to run it
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.