R what does 2 commas mean?

I am considering an example for the knnflex package, and they install a training and testing kit using the following:

 train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) 

My questions are how this differs from:

 train <- rbind(iris3[1:25,1], iris3[1:25,2], iris3[1:25,3]) test <- rbind(iris3[26:50,1], iris3[26:50,2], iris3[26:50,3]) 
+4
source share
3 answers

Two commas mean that there were more than two dimensions, and you selected all the dimension elements that could be indicated between the two commas. For example, imagine a cube instead of a square, with all the data in it. You can select the line, height and depth. If you select [row, depth], then you will select the whole column in the cube at that row and depth. The principle is the same as for large sizes, but more difficult to describe.

+4
source

Why don't you just give it a try?

 > train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) > test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) > train <- rbind(iris3[1:25,1], iris3[1:25,2], iris3[1:25,3]) Error in iris3[1:25, 1] : incorrect number of dimensions > test <- rbind(iris3[26:50,1], iris3[26:50,2], iris3[26:50,3]) Error in iris3[26:50, 1] : incorrect number of dimensions 

More generally, leaving the index unspecified, selects all records for this index:

 > mtx<-matrix(c(1,2,3,4),nrow=2) > mtx [,1] [,2] [1,] 1 3 [2,] 2 4 > mtx[1,] [1] 1 3 > mtx[,1] [1] 1 2 
+4
source

The difference between the diaphragm and the iris 3, iris3 is a three-dimensional matrix, contains the same data as the iris. But he stores it in different ways. You can see the diaphragm as a two-dimensional matrix. Check the link below https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html

0
source

Source: https://habr.com/ru/post/1382782/


All Articles