Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

  1. Create matrix dataset & querry characteristics
z <- matrix(5:12,nrow=4)
z
##      [,1] [,2]
## [1,]    5    9
## [2,]    6   10
## [3,]    7   11
## [4,]    8   12
length(z) #to querry length
## [1] 8
class(z) #to querry class
## [1] "matrix" "array"
dim(z) #to querry dimension
## [1] 4 2
  1. Row extracted from matrix in vector format, format determined, dimension reduction surpressed
r <- z[3,] #row extraction from matrix
attributes(z) #test_1 to confirm that data is in vector instead of matrix format
## $dim
## [1] 4 2
attributes(r) 
## NULL
str(z) #test_2 to confirm that data is in vector instead of matrix format
##  int [1:4, 1:2] 5 6 7 8 9 10 11 12
str(r)
##  int [1:2] 7 11
r <- z[3,, drop=FALSE] #to avoid problem above
r
##      [,1] [,2]
## [1,]    7   11
dim(r)
## [1] 1 2
class(r)
## [1] "matrix" "array"
  1. Naming columns in matrix
z
##      [,1] [,2]
## [1,]    5    9
## [2,]    6   10
## [3,]    7   11
## [4,]    8   12
colnames(z) #to check columns names
## NULL
colnames(z) <- c("a","b") #to name columns
colnames(z) #to check columns names
## [1] "a" "b"
z
##      a  b
## [1,] 5  9
## [2,] 6 10
## [3,] 7 11
## [4,] 8 12
  1. To record data matrix for the 1st test
firsttest <- matrix(nrow=3,ncol=2)
firsttest[1,1] <- 43
firsttest[2,1] <- 29
firsttest[1,2] <- 50
firsttest[2,2] <- 20
firsttest[3,1] <- 59
firsttest[3,2] <- 65
firsttest
##      [,1] [,2]
## [1,]   43   50
## [2,]   29   20
## [3,]   59   65
  1. To record data matrix for the 2nd test
secondtest <- matrix(nrow=3,ncol=2)
secondtest[1,1] <- 85
secondtest[2,1] <- 75
secondtest[1,2] <- 65
secondtest[2,2] <- 25
secondtest[3,1] <- 35
secondtest[3,2] <- 45
secondtest
##      [,1] [,2]
## [1,]   85   65
## [2,]   75   25
## [3,]   35   45
  1. Creating datastructures from invidual matrixes
tests <- array(data=c(firsttest,secondtest),dim=c(3,2,2)) #to create datastructure from invidual matrixes
attributes(tests) #to quity attributes
## $dim
## [1] 3 2 2
tests[3,2,1] #to query value
## [1] 65
tests
## , , 1
## 
##      [,1] [,2]
## [1,]   43   50
## [2,]   29   20
## [3,]   59   65
## 
## , , 2
## 
##      [,1] [,2]
## [1,]   85   65
## [2,]   75   25
## [3,]   35   45