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/
相关推荐
伐尘12 分钟前
【Qt】QTableWidget 自定义排序功能实现
开发语言·qt
多多*40 分钟前
上传文件相关业务,采用策略模式+模版方法模式进行动态解耦
java·开发语言
赴前尘1 小时前
Go 通道非阻塞发送:优雅地处理“通道已满”的场景
开发语言·后端·golang
weixin_456904271 小时前
以太网与工业以太网通信C#开发
开发语言·c#
野猪亨利6672 小时前
Qt day1
开发语言·数据库·qt
lastHertz2 小时前
Golang 项目中使用 Swagger
开发语言·后端·golang
惜月_treasure2 小时前
LlamaIndex多模态RAG开发实现详解
开发语言·python·机器学习
isaki1372 小时前
qt day1
开发语言·数据库·qt
流星白龙2 小时前
【Qt】4.项目文件解析
开发语言·数据库·qt
iuuia2 小时前
05--JavaScript基础语法(1)
开发语言·javascript·ecmascript