当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 seq.int()用法及代码示例


R 语言中的 seq.int() 函数用于返回指定范围内的数字列表。

用法: seq.int(from, to, by)

参数:
from:指定范围从
to:指定范围至
by:指定的数字,它通过返回的数字跳转

范例1:


# R program to illustrate
# seq.int function
  
# Calling seq.int() function
seq.int(0, 5)
seq.int(-2, 6)
seq.int(-3, 7)
seq.int(-7, 0)

输出:

[1] 0 1 2 3 4 5
[1] -2 -1  0  1  2  3  4  5  6
[1] -3 -2 -1  0  1  2  3  4  5  6  7
[1] -7 -6 -5 -4 -3 -2 -1  0

范例2:


# R program to illustrate
# seq.int function
  
# Calling seq.int() function
seq.int(2, 10, by = 2)
seq.int(0, 5, by = 1)
seq.int(5, 50, by = 10)

输出:

[1]  2  4  6  8 10
[1] 0 1 2 3 4 5
[1]  5 15 25 35 45

相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Get a List of Numbers in the Specified Range in R Programming – seq.int() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。