为什么 R 中的向量索引从 1 开始,而不是 0? [英] Why do vector indices in R start with 1, instead of 0?

查看:55
本文介绍了为什么 R 中的向量索引从 1 开始,而不是 0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 中的向量索引以 1 开头,而不是通常的 0 开头的原因是什么?

What is the reason that vector indices in R start with 1, instead of the usual 0?

示例:

> arr<-c(10,20)
> arr[0]
numeric(0)
> arr[1]
[1] 10
> arr[2]
[1] 20

他们是否只是想存储有关向量的额外信息,但除了作为向量的第一个元素之外,不知道将其存储在哪里?

Is it just that they want to store extra information about the vector and didn't know where to store it except as the vector's first element?

推荐答案

FORTRAN 是一种从 1 开始数组的语言.数学家处理的向量总是从分量 1 开始并经过 N.线性代数约定从行和列开始编号为 1 并经过 N.

FORTRAN is one language that starts arrays at 1. Mathematicians deal with vectors that always start with component 1 and go through N. Linear algebra conventions start with row and column numbered 1 and go through N as well.

C 以 0 开头,因为指针算法隐含在下面.Java、JavaScript、C++ 和 C# 紧随 C.

C started with zero because of the pointer arithmetic that was implicit underneath. Java, JavaScript, C++, and C# followed suit from C.

这篇关于为什么 R 中的向量索引从 1 开始,而不是 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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