Objects are created in R by using two operators <- and =
R can be used as a simple calculator; it is sufficient to write the equation in the console as shown in the below figure
We can use operations we need like
*, -, +, /
R can be used to create sequences as
shown in below figure
Vectors
Vectors are ordered collection of
data of the same elementary type. We can have a vector of characters, boolean
values or numbers. The below figure shows examples for vectors.
It is impossible that we can bind
two vectors of different types like vector of characters and vector of numbers.
Manipulations
Some manipulation can be done as
shown below
Matrix
Like the vectors, matrices can not
contain different types of elements. For example, if the matrix contains
numbers only; thus it can not contain characters at the same time.
However, the number of columns must
not be equal to the number of rows. All rows must have the same length; also,
the columns must have the same length. Matrices can be made using matrix()
function. The below figure shows an example of matrix.
The argument data can be used to add
data to matrix. byrow can take a TRUE value, this means that the data will be
inserted to matrix row by row. In contrast, byrow can take FALSE value which
mean that the data will be inserted column by column. The below examples shows
the insertion process.
Data Frames
Data frames are like the matrices
from the structure point of view. They contain rows and columns. Data frames
differ from matrices by a principal point: the elements of row or a columns may
be of different types. The below figure shows an example of data frames.
0 Comments