Session - 3 - 4 - Data Types and Data Structures
Session - 3 - 4 - Data Types and Data Structures
Understanding datasets
Where
vector contains the elements for the matrix
nrow and ncol specify the row and column dimensions,
dimnames contains optional row and column labels
The option byrow indicates whether the matrix should be filled in by row (byrow=TRUE) or by column
(byrow=FALSE).
Creating a Matrix
y <- matrix(1:20, nrow=5, ncol=4)
y <- matrix(1:20, nrow=5, ncol=4, byrow = TRUE)
y <- matrix(1:20, nrow=5, ncol=4, byrow = False)
X[i,] refers to the ith row of matrix X, X[,j] refers to the jth column, and
X[i, j] refers to the ij th element, respectively.
Creating a Matrix - Exercise
Create the following Matrix with name GroundsandWins
Where
vector contains contains the data for the array
dimensions is a numeric vector giving the maximal index for each dimension
dimnames is an optional list of dimension labels
Arrays
Arrays are similar to matrices but can have more than two dimensions. They’re created
with an array function of the following form:
If I must store 36 elements (1 to 36) what should I change in the above code ?
Data Frames
A data frame is more general than a matrix in that different columns can contain different
modes of data (numeric, character, and so on).