I'm looking at an example for the knnflex
package and they setup a training and test set 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 is how does this differ 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])
Two commas means there were more than two dimensions and you selected all of the items in the dimension that could have been specified between the two commas. For example, imagine a cube instead of a square, with all of the data in it. You can select row, height, and depth. If you select [row,,depth], then you will have selected an entire column in the cube at that row and depth. The principle is the same up to larger dimensions but harder to describe.
Why don't you just 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 an index unspecified selects all entries for that 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With