-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.R
More file actions
54 lines (40 loc) · 972 Bytes
/
Matrix.R
File metadata and controls
54 lines (40 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Create matrix
num<-matrix(c(1:9), nrow = 3, ncol = 3 )
num
#row wise
num<-matrix(c(1:9), nrow = 3, ncol = 3, byrow = TRUE)
num
acessories<-matrix(c("Ring","Watch","Perfume","Chain"), nrow = 2, ncol = 2,
byrow = TRUE)
acessories
#access matrix
num[1,2]
num[,2]
num[1,]
num[,]
row_names<-c("R1","R2")
col_names<-c("C1","C2")
mat<-matrix(mat, nrow = 2, ncol = 2, byrow = TRUE,
dimnames = list(row_names,col_names))
row_names<-c("R1","R2","R3","R4","R5")
col_names<-c("C1","C2","C3","C4","C5")
mat<-matrix(c(1:20), nrow = 5, ncol = 5, byrow = TRUE,
dimnames = list(row_names,col_names))
mat
mat["R1","C2"]
mat["R1",]
mat["R4","C3"]
# transpose means row wise to col wise, col wise to row wise
t(mat)
#rbind add row
mat_modify<-rbind(mat,"R6"=c(22,24,26,28,30))
mat_modify
#cbind add column
mat_modify<-cbind(mat,"C6"=c(17,18,19,20,21))
mat_modify
#built in
str(mat)
summary(mat)
dim(mat)
rownames(mat)
colnames(mat)