在 R 中,负索引有什么作用? [英] In R, what does a negative index do?
本文介绍了在 R 中,负索引有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将程序的一部分(不足以编译和运行)从 R 移植到 C++.我对 R 不熟悉.我已经使用在线参考资料做得很好,但被以下行难住了:
I am porting part of a program (not enough to compile and run) from R to C++. I am not familiar with R. I have done okay using the references online, but was stumped by the following line:
cnt2.2<-cnt2[,-1]
我猜:
cnt2
是一个二维矩阵cnt2.2
是一个用句点."声明的新变量.使用与字母字符相同的方式.<-
是一个赋值.[,-1]
访问数组的一部分.我认为[,5]
表示所有行,仅第 5 列.如果这是正确的,我不知道 -1 指的是什么.
cnt2
is a 2 dimensional matrixcnt2.2
is a new variable being declared with a period '.' used the same way an alphabetic character would be.<-
is an assignment.[,-1]
accesses part of the array. I thought[,5]
meant all rows, 5th column only. If this is correct, I have no idea what -1 refers to.
推荐答案
这在手册的 2.7 节中有介绍:http://cran.r-project.org/doc/manuals/R-intro.html#Index-vectors
This is covered in section 2.7 of the manual: http://cran.r-project.org/doc/manuals/R-intro.html#Index-vectors
它是 cnt2
对象的负索引,指定除第一列之外的所有行和所有列.
It is a negative index into the cnt2
object specifying all rows and all columns except the first column.
这篇关于在 R 中,负索引有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文