( (1) ) (1) 2 5 3 ( (2) ) (1) 21 ( (3) ) (1) 3 ( (4) ) Function (X) .Primitive ("Sin")
( (1) ) (1) 2 5 3 ( (2) ) (1) 21 ( (3) ) (1) 3 ( (4) ) Function (X) .Primitive ("Sin")
[[2]]
[1] 21
[[3]]
[1] 3
[[4]]
function (x) .Primitive("sin")
Matrices in R
A matrix is a two dimensional rectangular data set. It can be created using a vector input to
the matrix function.
# create a matrix
M = matrix(c('a','a','b','c','b','a'),nrow = 3,byrow = TRUE)
print(M)
Arrays in R
While matrices are confined to two dimensions, arrays can be of any number of dimensions.
The array function takes a dim attribute which creates the required number of dimensions.
In the below example we create an array with two elements which are 3*3 matrices each.
# create an array
a <- array(c('green','yellow'),dim = c(3,3,2))
print(a)
if we run the code we get
,,2
Factors in R
Factors are the r-objects which are created to using a vector.
It stores the vector along with the distinct values of the elements in the vector as the labels.
The labels are always character irrespective of whether it is numeric or character or Boolean etc, in
the input vector.
They are useful in statistical modelling.
Factors are created using the factor function.
The n levels function gives us the count of levels.
# create a vector
apple_colors <-
c('green','green','yellow','red','red','green')
Data frames in R
Data frames are tabular data objects.
Unlike in a matrix in data frame each column can contain different modes of data.
The first column can be a numeric while the second column can be character and third column can
be logical.
It is a list of vectors of equal length.
Data frames are created using the data frame function.
Data frame in R
# create the data frame
Arithmetic operators:
These operators are used to carry out mathematical operations like addition and multiplication.here
is a list of arithmetic operators available in R
Operator Description
+ addition
- Subtraction
Multiplication
/ division
^ or ** exponentiation
X%%y modulus (x mod y)
X%/%y integer division
Relational operators:
Relational operators are used to compare between values. Here is a list of relational operators
available in R
< less than
Greater than
<= less than or equal to
>= greater than or equal to
= equal to
!= not equal to