A vector in R can contain any number of elements, but all of the elements must be of the same type – that is a vector cannot contain a mix of numbers, logical, and character types.
The c() function is used for creating the Vector.
Factor
The factor() function is used for encoding a vector as a factor. A factor() function is a special case of vector that is used for representing nominal or categorical or ordinal data.
List
A list is used for storing an ordered set of elements. While a vector requires all its elements to be of the same type, a list allows different types of elements.
The list() function is used for creating the list.
Matrix
A matrix is a two-dimensional table with rows and columns of data. Like vectors, R matrices can contain one type of data and are typically used for only storing numeric data.
The matrix() function is used for creating a matrix.
The function cbind() can be used for constructing a matrix using vectors.
Data Frame
The data.frame() function is used for constructing the data frame.
The cbind() function is used for adding a column into the data frame. A column into the data frame can be added using a new column name in the format – frame$column-name.
The rbind() function is used for adding a row into the data frame. A new row can be added using nrow() function.
The merge() function is used for merging two data frames.
Number of rows and columns in the data frame can be found by nrow(), ncol(), and dim() functions.
Row and Columns names can be found by nrownames(), ncolnames(), and dimnames() functions.