gpt4 book ai didi

r - 为什么从索引零开始对向量进行切片是有效的?

转载 作者:行者123 更新时间:2023-12-04 17:43:04 31 4
gpt4 key购买 nike

v <- 1:10

于是我无意中发现:
v[0:10] == v[1:10]

输出:
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

如何?首先,我认为 R 指数从 1 开始?

最佳答案

来自 R language definition (第 3.4.1 节,“按向量索引”,“整数”):

A special case is the zero index, which has null effects: x[0] is an empty vector and otherwise including zeros among positive or negative indices has the same effect as if they were omitted.



Another SO question asks "why is this useful"? ,没有很多令人满意的答案:这是一个有趣的问题,但似乎是 r-devel@r-project.org 的主题。而不是...

关于r - 为什么从索引零开始对向量进行切片是有效的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53854858/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com