In R, what does a negative index do?

后端 未结 3 1629
情话喂你
情话喂你 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:07

    Negative indices specify dropping (rather than retaining) particular elements ... so x[,-1] specifies dropping the first column (rows are the first dimension, before the comma, and columns are the second dimension, after the comma). From ?"[" ( http://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.html ):

    For ‘[’-indexing only: ‘i’, ‘j’, ‘...’ can be logical vectors, indicating elements/slices to select. Such vectors are recycled if necessary to match the corresponding extent. ‘i’, ‘j’, ‘...’ can also be negative integers, indicating elements/slices to leave out of the selection.

提交回复
热议问题