You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Matrix dimensions can be named, using the commands `dimnames`, `rownames`, or `colnames`.
232
244
Names can be assigned also at the definition time:
@@ -243,13 +255,26 @@ colnames(Xmat) <- c(1:5)
243
255
244
256
# Read the row names and column names
245
257
rownames(Xmat)
258
+
259
+
# > [1] "1" "2" "3" "4"
260
+
246
261
colnames(Xmat)
247
262
263
+
# > [1] "1" "2" "3" "4" "5"
264
+
248
265
# Assign using dimnames
249
266
dimnames(Xmat) <- list(c(1:4), c(1:5)) # Notice that in this case we need a list
250
267
251
268
# Assign at the definition
252
-
Xmat <- matrix(sample(20), 4, 5, dimnames = list(c(1:4), c(1:5)) # Same as dimnames command
269
+
Xmat <- matrix(sample(20), 4, 5, dimnames = list(c(1:4), c(1:5))) # Same as dimnames command
270
+
271
+
Xmat
272
+
# > Xmat
273
+
# 1 2 3 4 5
274
+
# 1 6 2 18 15 4
275
+
# 2 13 9 8 7 20
276
+
# 3 10 14 1 19 5
277
+
# 4 11 3 16 12 17
253
278
```
254
279
255
280
An **array** is the matrix extension to more than 2-dimensions. For instance, the following command will assign a 3-dimensional array of dimensions (5 x 6 x 10) to the variable ```myArray```:
@@ -451,4 +476,4 @@ Here, it is possible to find nice examples of data graphs generated using ```ggp
0 commit comments