R語(yǔ)言seq()函數(shù)的調(diào)用方法
看到有很多讀者瀏覽了這篇文章,心里很是開心,為了能夠更好地幫助大家,決定再修改一下,幫助大家更好地理解。
--------修改于:2018年4月28日
為了方便大家在開發(fā)環(huán)境中直接實(shí)驗(yàn)測(cè)試代碼,下面,我將說(shuō)明和函數(shù)的用法全部用英文給出(避免亂碼),并加以注釋,希望能夠?qū)Υ蠹矣兴鶐椭?/p>
首先,我們來(lái)看一個(gè)seq()函數(shù)應(yīng)用的實(shí)例!
x <- seq(0, 10, by = 0.01) y <- sin(x) plot(y)
下面,我們來(lái)看函數(shù)的主要使用方法!
注意:在本文調(diào)用函數(shù)時(shí),均采用寫出入口參數(shù)名的方法,比如:
seq(from = 1, to = 2)
這樣函數(shù)的調(diào)用更加清晰,在調(diào)用較多函數(shù)時(shí),不會(huì)發(fā)生混亂和參數(shù)匹配錯(cuò)誤。
方式一:seq(from, to)
from:生成向量的起點(diǎn),to:生成向量的終點(diǎn),默認(rèn)步長(zhǎng)為1(可修改)
a <- seq(from = 1, to = 2) # [1, 2]
方式二:seq(from, to, by = )
by:向量元素之間的步長(zhǎng)
a <- seq(from = 1, to = 3, by = 0.5) # [1, 1.5, 2, 2.5, 3]
方式三:seq(from, to, length.out = )
length.out:向量中元素?cái)?shù)目
a <- seq(from = 1, to = 3, length.out = 5) # [1, 1.5, 2, 2.5, 3]
方式四:seq(along.with = )
along.with:表示生成的向量為現(xiàn)有一向量元素的索引
x <- c(1.2, 5.2, 6.3, 4.6) a <- seq(along.with = x) # [1, 2, 3, 4]
方式五:seq(from)
該方式和方式四功能相似
x <- c(1.2, 5.2, 6.3, 4.6) a <- seq(from = x) # [1, 2, 3, 4]
方式6:seq(length.out = )
生成從1開始,步長(zhǎng)為1,長(zhǎng)度為length.out的向量
a <- seq(length.out = 5) # [1, 2, 3, 4, 5]
上述幾種方式為較為常見的方式,詳細(xì)的函數(shù)說(shuō)明如下:
Sequence Generation
Description
Generate regular sequences. seq is a standard generic with a default method. seq.int is a primitive which can be much faster but has a few restrictions. seq_along and seq_len are very fast primitives for two common cases.
---------------------------------------------
Usage
seq(...)
## Default S3 method:
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
length.out = NULL, along.with = NULL, ...)
seq.int(from, to, by, length.out, along.with, ...)
seq_along(along.with)
seq_len(length.out)
---------------------------------------------
Arguments
1:...
arguments passed to or from methods.
2:from, to
the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument.
3:by
number: increment of the sequence.
4:length.out
desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional.
5:along.with
take the length from the length of this argument.
參考:https://blog.csdn.net/jiluben/article/details/40024607
到此這篇關(guān)于R語(yǔ)言seq()函數(shù)的調(diào)用方法的文章就介紹到這了,更多相關(guān)R語(yǔ)言seq()函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
R語(yǔ)言中常見的幾種創(chuàng)建矩陣形式總結(jié)
這篇文章主要給大家介紹了關(guān)于R語(yǔ)言中常見的幾種創(chuàng)建矩陣形式的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03R語(yǔ)言學(xué)習(xí)數(shù)據(jù)獲取操作示例詳解
這篇文章主要為大家介紹了R語(yǔ)言學(xué)習(xí)數(shù)據(jù)獲取操作示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08R語(yǔ)言繪制數(shù)據(jù)可視化Dumbbell?plot啞鈴圖
這篇文章主要為大家介紹了R語(yǔ)言繪制數(shù)據(jù)可視化Dumbbell?plot啞鈴圖的實(shí)現(xiàn)步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02R語(yǔ)言 解決安裝ggplot2報(bào)錯(cuò)的問(wèn)題
這篇文章主要介紹了R語(yǔ)言 解決安裝ggplot2報(bào)錯(cuò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-04-04大數(shù)據(jù)分析R語(yǔ)言RStudio使用超詳細(xì)教程
RStudio是用于R編程的開源工具,這篇文章主要介紹了大數(shù)據(jù)分析R語(yǔ)言RStudio使用教程和一些RStudio的重要技巧,竅門和快捷方式,可快速將您變成RStudio高級(jí)用戶,感興趣的朋友跟隨小編一起看看吧2021-03-03