In R, what does a negative index do?

后端 未结 3 1630
情话喂你
情话喂你 2020-12-01 18:46

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 th

3条回答
  •  温柔的废话
    2020-12-01 19:19

    1) cnt2 is a 2 dimensional matrix

    From the code you provided it is indeed a 2-dimensional structure of some sort (quite possibly a matrix).

    2) cnt2.2 is a new variable being declared with a period '.' used the same way an alphabetic character would be.

    Correct.

    3) <- is an assignment.

    Correct.

    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.

    [,-1] selects all columns except column 1. Note that, unlike in C++, indices in R start from one rather than zero.

提交回复
热议问题