Vectors
The function c(), which stands for concatenate, is useful for creating vectors.
Another useful function for creating vectors is the seq() function, which generates sequences.
Subsetting lets us access specific parts of a vector by using square brackets to access elements of a vector.
codes[2]
Lists
A list is different from a vector because it can hold many different types of R objects inside it, including other lists.
To create list
First, we have the number 1. Then, a character string, "2", followed by the character string "Hello", the character string "cat", the number 12, and then a nested list, which contains the numbers 1, 2, and 3.
Accessing these different parts of the list that we just created is slightly different—now, you are using list indexing, which means using double square brackets to look at the different items.
[1] cat
Matrices
A matrix is a 2D vector with rows and columns. In R, one requirement for matrices is that every data element stored inside it be of the same type. This allows you to perform arithmetic operations with matrices.
To create matrix
Set the row and column names of matrix1 with the following:
colnames(matrix1) <- c("one", "two", "three")
To access certain element
[1] 4
Dataframes
A dataframe in R is a 2D object where the columns can contain data of different classes and types. This is very useful for practical data storage.
Dataframes can be created by using as.data.frame() on applicable objects or by column- or row-binding vectors using cbind.data.frame() or rbind.data.frame().
example_df <- as.data.frame(list_for_df)