在R中,负指数有什么作用? [英] In R, what does a negative index do?

查看:274
本文介绍了在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]

我在猜测:


  1. cnt2 是一个二维矩阵

  2. cnt2.2 是一个声明为句点'。'的新变量。使用与字母字符相同的方式。

  3. < ; - 是一项任务。

  4. [, - 1] 访问部分数组。我认为 [,5] 表示所有行,仅限第5列。如果这是正确的,我不知道-1指的是什么。

  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.


推荐答案

这是本手册第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

这是<$ c $的负面指数c> cnt2 指定除第一列以外的所有行和所有列的对象。

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

这篇关于在R中,负指数有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆