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/
相关推荐
过期动态5 小时前
JDBC高级篇:优化、封装与事务全流程指南
android·java·开发语言·数据库·python·mysql
WizLC5 小时前
【Java】各种IO流知识详解
java·开发语言·后端·spring·intellij idea
傻啦嘿哟5 小时前
实战:用Splash搞定JavaScript密集型网页渲染
开发语言·javascript·ecmascript
Knight_AL5 小时前
Java 线程池预热(Warm-up)实战:开启与不开启到底差多少?
java·开发语言
liwulin05066 小时前
【PYTHON】COCO数据集中的物品ID
开发语言·python
小鸡吃米…6 小时前
Python - XML 处理
xml·开发语言·python·开源
APIshop6 小时前
Java爬虫1688详情api接口实战解析
java·开发语言·爬虫
Mr.Jessy7 小时前
JavaScript高级:深浅拷贝、异常处理、防抖及节流
开发语言·前端·javascript·学习
bing.shao7 小时前
Golang 高并发秒杀系统踩坑
开发语言·后端·golang
liwulin05067 小时前
【PYTHON-YOLOV8N】关于YOLO的推理训练图片的尺寸
开发语言·python·yolo