R notes[2]

文章目录

sequence

  1. organized equence is a regular facility of R language,it can be generated by the seq() function.of couse ,in oder to make arbitrary list, the c() is used to achieve the task,that is explained at the previous note.
    the seq funtcion forms as follows.
r 复制代码
seq(from_value,to_value,step)
r 复制代码
> seq(1,10,2)
[1] 1 3 5 7 9
> seq(1,10,1)
 [1]  1  2  3  4  5  6  7  8  9 10
> seq(1,10,7)
[1] 1 8
> seq(10,1,-1)
 [1] 10  9  8  7  6  5  4  3  2  1

you may assign arguments in keyword,for example, seq(to=1,from=10,by=-1).

the rep function also make sequence which is different from seq,rep puts the same elements together into a list with specified number of times by default.

r 复制代码
> rep(-1,3)
[1] -1 -1 -1
r 复制代码
> rep(1,each=2)
[1] 1 1
> rep(1,times=2)
[1] 1 1
> rep(1,2)
[1] 1 1

We need to pay attention that if given element is a list,the rep have a argument named each which will repeatedly generate each element of given list for specified number of times and then arrange them in original order of each element .

r 复制代码
> a<-c(1,2)
> rep(a,3)
[1] 1 2 1 2 1 2
> rep(a,times=3)
[1] 1 2 1 2 1 2
> rep(a,each=3)
[1] 1 1 1 2 2 2

references

  1. https://cran.r-project.org/doc/manuals/
相关推荐
高山有多高21 分钟前
从 0 到 1 保姆级实现C语言双向链表
c语言·开发语言·数据结构·c++·算法·visual studio
Lucis__37 分钟前
C++相关概念与语法基础——C基础上的改进与优化
c语言·开发语言·c++
草莓熊Lotso38 分钟前
《算法闯关指南:优选算法--滑动窗口》--14找到字符串中所有字母异位词
java·linux·开发语言·c++·算法·java-ee
MATLAB代码顾问2 小时前
Python实现手榴弹爆炸算法(Grenade Explosion Method, GEM)(附完整代码)
开发语言·python·算法
人工干智能2 小时前
Python的大杀器:Jupyter Notebook处理.ipynb文件
开发语言·python·jupyter
zpf_叶绿体学编程2 小时前
一命速通:Go 语言操作 Office Excel 文档,从入门到实战解析
开发语言·golang·excel
running thunderbolt2 小时前
c++:SLT容器之set、map详解
开发语言·c++
跳跳的向阳花2 小时前
02、Python从入门到癫狂:函数与数据容器
开发语言·python
m0_635647483 小时前
信号与槽已经使用connect语句连接,并且参数也匹配,但是发送信号以后不执行槽函数?
开发语言·qt
十年一梦实验室3 小时前
【AI解析】一个用 C#编写的类,用于通过以太网非过程命令与 Keyence CV-X 系列视觉系统进行通信
开发语言·c#