當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。