Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
751 views
in Technique[技术] by (71.8m points)

syntax - In R, what does a negative index do?

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]

I am guessing:

  1. cnt2 is a 2 dimensional matrix
  2. cnt2.2 is a new variable being declared with a period '.' used the same way an alphabetic character would be.
  3. <- is an assignment.
  4. [,-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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is covered in section 2.7 of the manual: http://cran.r-project.org/doc/manuals/R-intro.html#Index-vectors

It is a negative index into the cnt2 object specifying all rows and all columns except the first column.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...