R语言 seq()函数的调用方法
我们来看一个seq()函数应用的实例!
x <- seq(0, 10, by = 0.01) y <- sin(x) plot(y)
下面,我们来看函数的主要使用方法!
注意:在本文调用函数时,均采用写出入口参数名的方法,比如:
seq(from = 1, to = 2)
这样函数的调用更加清晰,在调用较多函数时,不会发生混乱和参数匹配错误。
方式一:seq(from, to)
from:生成向量的起点,to:生成向量的终点,默认步长为1(可修改)
a <- seq(from = 1, to = 2) # [1, 2]
方式二:seq(from, to, by = )
by:向量元素之间的步长
a <- seq(from = 1, to = 3, by = 0.5) # [1, 1.5, 2, 2.5, 3]
方式三:seq(from, to, length.out = )
length.out:向量中元素数目
a <- seq(from = 1, to = 3, length.out = 5) # [1, 1.5, 2, 2.5, 3]
方式四:seq(along.with = )
along.with:表示生成的向量为现有一向量元素的索引
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开始,步长为1,长度为length.out的向量
a <- seq(length.out = 5) # [1, 2, 3, 4, 5]
上述几种方式为较为常见的方式,详细的函数说明如下:
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
关于R语言seq()函数的调用方法的文章就介绍至此,更多相关R语言seq()函数内容请搜索编程宝库以前的文章,希望大家多多支持编程宝库!
本文主要介绍了R语言文本文件读写,分享给大家,具体如下:read.table(file,sep,hesder)#file 文件路径#sep 分隔符#header 第一行是不是列名(如果第一行 ...