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/
相关推荐
莎士比亚的文学花园3 小时前
Linux驱动开发(3)——设备树
开发语言·javascript·ecmascript
图码3 小时前
如何用多种方法判断字符串是否为回文?
开发语言·数据结构·c++·算法·阿里云·线性回归·数字雕刻
U盘失踪了3 小时前
python curl转python脚本
开发语言·chrome·python
charlie1145141913 小时前
Linux 字符设备驱动:cdev、设备号与设备模型
linux·开发语言·驱动开发·c
handler013 小时前
Linux 内核剖析:进程优先级、上下文切换与 O(1) 调度算法
linux·运维·c语言·开发语言·c++·笔记·算法
FQNmxDG4S3 小时前
Java泛型编程:类型擦除与泛型方法的应用场景
java·开发语言·python
我星期八休息4 小时前
IT疑难杂症诊疗室:AI时代工程师Superpowers进化论
linux·开发语言·数据结构·人工智能·python·散列表
热心网友俣先生4 小时前
2026年第二十三届五一数学建模竞赛C题超详细解题思路+各问题可用模型推荐+部分模型结果展示
c语言·开发语言·数学建模
01漫游者4 小时前
JavaScript函数与对象增强知识
开发语言·javascript·ecmascript
IGAn CTOU4 小时前
Java高级开发进阶教程之系列
java·开发语言