简体   繁体   English

R 2个逗号是什么意思?

[英]R what does 2 commas mean?

I'm looking at an example for the knnflex package and they setup a training and test set using the following: 我正在查看knnflex软件包的示例,他们使用以下方法设置了培训和测试集:

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])

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

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. 该原则在更大的维度上是相同的,但更难以描述。

The difference is between iris and iris3, iris3 is a 3- dimensional matrix, contains the same data as iris. 区别在于虹膜和虹膜3,虹膜3是一个三维矩阵,包含与虹膜相同的数据。 But it stores it differently. 但它存储的方式不同。 You can see iris as a bidimensional matrix Check the link below https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html 您可以将虹膜视为二维矩阵检查以下链接https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM